Reputation: 24572
I have:
<tr id='id1' class='X-** other-class a-class'>
Where the * can be any number.
If I want to replace the class name that starts with X-99 then how can I do this?
Upvotes: 1
Views: 55
Reputation: 144689
try this:
if ($('#id1').get().className) {
$('#id1').get().className = $('#id1').get().className.replace(/\bX\-.*?\b/g, 'X-99');
} else {
$('#id1').addClass('X-99')
}
Upvotes: 1
Reputation: 27594
Try those selectors:
// all trs with X-* class (that is: classes which starts with X-)
$("tr[class^='X-']")
// all trs with X-99 class
$("tr.X-99")
Then you can use addClass
or removeClass
to set or unset classes.
Upvotes: 0
Reputation: 1582
jQuery(".X-99").removeClass(".X-99"); //class level
jQuery("#id1").removeClass(".X-99"); //id level
what do you want to do exactly ?
Upvotes: 0