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

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

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -