I have an element with more than 5 classes. I just need to replace the class in first position without affecting the rest of them ..
I don't want to replace all classes (I have tried with .attr('class','class1 class2 class3 class4 class5') , .prop , .switchclass etc)..
You don't have to use jQuery for that: just address DOM Element and its
classNameattribute directly. For example (assuming$elis a jQuery object wrapped aroung the element you want to change):This replaces the first class of
$elwithreplacementClassstring.Alternatively, you can use
attrto do essentially the same: