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
Post a Comment