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
  • 43,881
  • 8
  • 73
  • 106
heymega
  • 8,825
  • 5
  • 40
  • 57

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