11

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.

Victor
  • 5,493
  • 1
  • 27
  • 28
Shijin TR
  • 7,516
  • 10
  • 55
  • 122

5 Answers5

22

A simple and elegant solution would be:

$(".class").removeClass("class");`
MeSo2
  • 450
  • 1
  • 7
  • 18
Adi
  • 2,074
  • 22
  • 26
10

Older thread, but in my case I wanted to remove a specific class from all child elements

 $('#parentDiv').find("*").removeClass("row-selected");
Elim Garak
  • 1,728
  • 1
  • 16
  • 21
9

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.

Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101
2

You need to use find to grab all the nested elements, then iterrate over them.

$('#message').find('*').each(function(){
     $(this).removeAttr('class');
})
shenku
  • 11,969
  • 12
  • 64
  • 118
0

It will work fine

    $('#message').find('*').removeAttr('class');
Shijin TR
  • 7,516
  • 10
  • 55
  • 122