david david - 2 months ago 9
jQuery Question

Function that to look up then perform task

I am trying to write a short script that looks to see if a class or id is present in then document. If it is then do the following:

$(".tab_item").removeClass("tab_item_color");
$(this).addClass("tab_item_color");

Answer

You can also do this

First Way

$(function() { 
    if ($('.yourClassName').length){
        $(".tab_item").removeClass("tab_item_color").addClass("YourNewClassName"); //It will swap your class.                          
    }
});

For more information you can also visit .length

Comments