I have the following html
<div class="row">
<div class="one someclass"></div>
<div class="two someclass"></div>
<div class="three someclass"></div>
</div>
<div class="row">
<div class="one someclass"></div>
<div class="two someclass"></div>
<div class="three someclass"></div>
</div>
And I want remove all one, two, three attribute
I tried
$(function () {
$('div').removeAttr('one', 'two', 'three');
});
but didn't work. I think this is wrong method. What should I do?
removeClass
accepts a space-delimited list of the class names to remove, so:
$("div.one, div.two, div.three").removeClass("one two three");
Assuming you're removing classes (like in your HTML) you can do the following
$('div').removeClass('one two three');
The documentation on removeClass
states:
One or more space-separated classes to be removed from the class attribute of each matched element.
Those aren't attributes, those are classes. Try:
$('div').removeClass('one two three');
Notice also that the function removeClass
accepts one argument, not three. Just pass all of the intended class names into that one argument.
The attribute is the word "class" itself in this case.
You are try to removing classes not attributtes:
Try with:
$('.someclass').removeClass('one two three');
Try this JQuery's removeClass
method,
//Normal Practice
$("div.one, div.two, div.three").removeClass("one two three");
//Best Practice.
$('div').find('.one, .two, .three').removeClass('one two three');
For your reference have look into this JQuery removeClass
来源:https://stackoverflow.com/questions/17488897/remove-multiple-classes-at-once