jquery - If statement for swapping class -


i using following code try , swap class if class name present on page;

$(function() {      if ($('.special').length){         $(".tab_item").removeclass("tab_item_color").addclass("tab_item_color");     } }); 

so in english: if class "special" present, remove .tab_item , add tab_item_color instead.

this want do. read correctly? should swapclass used?

you can use below code, have check special class exist in element

$(function() {      $('.tab_item').each(function(){         if($(this).hasclass("special")){              $(this).removeclass("tab_item").addclass("tab_item_color");         }     }); }); 

or

$(function() {      $('.tab_item.special').removeclass("tab_item").addclass("tab_item_color"); }); 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -