问题
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?
回答1:
removeClass accepts a space-delimited list of the class names to remove, so:
$("div.one, div.two, div.three").removeClass("one two three");
回答2:
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.
回答3:
Try with .removeClass()
like
$('div').removeClass('one two three');
see this LINK
回答4:
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.
回答5:
use removeClass() to remove classes
Try
$('div').removeClass('one,two,three');
回答6:
You are try to removing classes not attributtes:
Try with:
$('.someclass').removeClass('one two three');
回答7:
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