heymega
heymega

Reputation: 9391

Remove all attributes from every element inside a div

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

How can I achieve this with jQuery?

Upvotes: 2

Views: 4055

Answers (1)

Duncan Cowan
Duncan Cowan

Reputation: 495

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.

Upvotes: 3

Related Questions