7

Possible Duplicate:
How to remove all CSS classes using jQuery?

I have the following:

<div id="abc">
</div>

Inside that div there can be one only of the following:

<p class="message">
<p class="message error"></p>
<p class="message warning"></p>
<p class="message success"></p>
<p class="message loading"></p>

Is there a way that I can find and remove all classes from the <p> element?

0

4 Answers 4

18

You can do this:

$("#abc p").attr("class", "");

or

$("#abc p").removeClass();
3
  • What are you talking about, the jquery documentation doesn't say it's supported? The first line of the documentation says exactly that.
    – Daedalus
    Sep 21, 2012 at 1:35
  • 1
    It does directly say it, in the 2nd sentence of the first paragraph of the description of the function in the API doc Sep 21, 2012 at 1:36
  • OK, I didn't see that in the doc. You're right, it is supported there. Looking in the code, it does elem.className = "" when nothing is passed to .removeClass(). Post edited.
    – jfriend00
    Sep 21, 2012 at 1:36
6

If no class names are specified in the parameter, all classes will be removed.

Source.

Use removeClass() with no arguments.

4

You can use removeAttr method:

$('#abc p').removeAttr('class')
1

From the documentation, .removeClass()

$('#abc p').removeClass();