2

I need to remove all attributes (ids, classes, events, styles etc.) from every element inside a <div>.

How can I achieve this with jQuery?

Amit
  • 45,440
  • 9
  • 78
  • 110
heymega
  • 9,215
  • 8
  • 42
  • 61

1 Answers1

3

This is possible using a simple while loop:

$("div#myDiv").children().each(function() {
    while(this.attributes.length > 0)
        this.removeAttribute(this.attributes[0].name);
});

Where 'myDiv' is the ID of the parent div.

Duncan Cowan
  • 495
  • 3
  • 12