strawberry
strawberry

Reputation: 177

Jquery replace parent with first child

I'm trying to replace a dom parent with its first child and deleting all other children. It's not working. I got error: "Node cannot be inserted at the specified point in the hierarchy"

$("#over1").replaceWith($(this).children()[0]); 

Upvotes: 2

Views: 2401

Answers (1)

Gary Green
Gary Green

Reputation: 22395

this isn't referencing the #over1 element. Instead you should do:

$("#over1").replaceWith(function() { return $(':first', this); });

Upvotes: 4

Related Questions