DEV Community

Discussion on: How to replace arbitrary portions of HTML?

Collapse
 
yashints profile image
Yaser Adel Mehraban • Edited

I'd suggest get the parent node using JS and then replace an entire node with another node that you've built.

parent.replaceChild(newNode, oldChild);

Manipulating DOM by replacing HTML could be dangerous if any JS is depending on any part of that.

Collapse
 
sidvishnoi profile image
Sid Vishnoi

Or use oldChild.replaceWith(newChild)