Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

add class with jquery

//On button cick
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p:first").addClass("intro");
  });
});
</script>

//On page load
<script>
$(document).ready(function(){
  if ($( "#element" ).hasClass('className')) {
      $( "#element" ).removeClass( 'className');
  } else {
    $( "#element" ).addClass( 'className');
  }
});
</script>
Source by api.jquery.com #
 
PREVIOUS NEXT
Tagged: #add #class #jquery
ADD COMMENT
Topic
Name
3+1 =