Reputation: 1034
I have divs that have will sometimes have a 2 classes with a comma in between them. I did not code this by hand, it is generated by a webapp. I would like to remove the any commas in the class attribute and replace them with a space. How do I accomplish this? I have multiple classes, so I have to search for that character and replace that character only.
.each(function() {
var $el = $(this),
n = $el.attr("class").match(/cat-item-(.*)/)[1];
$el.addClass(n);
});
Upvotes: 1
Views: 862
Reputation: 24648
.each(function() {
var $el = $(this),
n = $el.attr("class");
$el.attr('class', n.replace(/,/g,' ') );
});
Upvotes: 0
Reputation: 4043
jQuery('whatever_youre_searching_to_update').each(function() {
var _sCurrClasses = jQuery(this).attr('class');
jQuery(this).attr('class', _sCurrClasses.replace(/,/g, ' '));
});
Upvotes: 4