Reputation: 16726
I have the following syntax in which I want to remove all css classes from the link tags. How can I do this using jquery?
<div id="nav">
<ul>
<li><a href="" class="foo">aa</a></li>
<li><a href="" class="bar">aa</a></li>
<li><a href="" class="yay">aa</a></li>
</ul>
</div>
Upvotes: 3
Views: 19685
Reputation: 458
You can use $("a").removeClass();
here is example: http://jsfiddle.net/UPsEK/
Upvotes: 1
Reputation: 101604
$('#nav ul li a').each(function(){
this.className = '';
});
Finds all anchors, based on div#nav
selector, and removes all class names.
Upvotes: 5
Reputation: 3644
If you want to remove every class then it's this:
$('#nav a').each(function(){
$(this).removeAttr('class');
});
Upvotes: 1
Reputation: 318508
You can use the removeClass()
method; if you call it without an argument it removes all classes:
$('#nav ul a').removeClass();
Description: Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
Obviously you can chain .addClass('someClass')
in the same call; you asked to change the class in your question's subject after all. ;)
Upvotes: 19