JSFiddle - React, Tailwind, and code Playground

by David Thomas

HTML

<div id="demo">This is the 'target' element, of id="demo". We'll insert a newly-created element <em>after</em> this one.</div>

JavaScript

HTMLElement.prototype.after = function(newNode){
    // 'this' refers to the DOM node to which this method is chained:
    this.parentNode.insertBefore(newNode, this.nextSibling);
}

var aNewNode = document.createElement('div'),
    nodeToActOn = document.getElementById('demo');
aNewNode.innerHTML = '<p>Some text in a paragraph of a newly-created node.</p>';

nodeToActOn.after(aNewNode);