How can I remove all classes that are not named "message" from an element?

Posted by Marilou on Stack Overflow See other posts from Stack Overflow or by Marilou
Published on 2012-09-21T03:34:07Z Indexed on 2012/09/21 3:37 UTC
Read the original article Hit count: 124

Filed under:

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 only the class from the <p> element that's NOT "message". I realize I could remove everything and then add what I need with .removeClass() but this won't work for me as after I previously added the message class I did some CSS changes and these will be lost if I remove all and then add again the message class.

© Stack Overflow or respective owner

Related posts about jQuery