Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove class from all child elements

Tags:

html

jquery

attr

I have a html like:

<table id="message">
    <tr class="clsaa1">
        <td>
            <div class="class3">
                <table class="sub_1">
                ----------------------
                ----------------------
                </table>
            <div>
        </td>
    </tr>
    <tr class="clsaa2">
        <td>
            <div class="class3">
                ----------------------
                ----------------------
            <div>
        </td>
    </tr>
</table>

I need to remove all class attributes inside #message.

I have tried

$('#message').siblings().removeAttr('class');

and

$('#message').children().removeAttr('class');

But this is not working.

like image 499
Shijin TR Avatar asked Mar 26 '14 05:03

Shijin TR


2 Answers

A simple and elegant solution would be:

$(".class").removeClass("class");`
like image 57
Adi Avatar answered Oct 02 '22 05:10

Adi


Instead of removeAttr('class') you can use removeClass("classname")

If you want to remove all the class values from its children, then do like

$('#message').find("*").prop("class","");

or even

$('#message').find('*') removeAttr('class');

Here is a fiddle.

like image 26
Mithun Satheesh Avatar answered Oct 02 '22 07:10

Mithun Satheesh