I have a
< div id="thisdiv" class="class1 class2 class3 class4 class5"> text < /div>
I need to be able to delete all classes after class3 with jQuery.
something like
$('#thisdiv').removeClass(all after class3);
OR
$('#thisdiv').attr('class', all from class1 to class3);
Please how can I do that?
You can try the following, but your classes might not be in the same order as they appear in the HTML source:
Here’s the fiddle: http://jsfiddle.net/FNUK2/
A more succinct way would be to just slice the string itself:
but I find working with arrays easier.
If you want to use it in the jQuery chain, you’ll have to first add it to jQuery’s prototype:
Here’s the fiddle: http://jsfiddle.net/FNUK2/11/