I want to remove matching class like type-one
before adding new class like type-two
HTML :
<div class="demo test">
<span>One</span>
<span>Two</span>
<span>Three</span>
</div>
jQuery :
$(document).on("click" ,".demo > span", function(){
$(this).addClass("active").siblings().removeClass("active");
$(this).parents(".demo").removeClass(function(i, c){
return c.match(/type-[a-z]{0,5}/);
})
$(this).parents(".demo").addClass("type-"+$(this).text().toLowerCase());
})
My code is still adding and adding , cant remove the old matching class.
What I am doing wrong ?
Demo : http://jsfiddle.net/X5JxV/