“How to replace an element and its content using vanilla JS - Go Make Things”

On sites with user-generated content I like to use Node.replaceWith() in conjunction with DOMPurify configured it to return a DocumentFragment.

Baldur Bjarnason @baldur