Start of main content
Insert HTML string after element
JavaScript, Browser · Oct 20, 2020

Inserts an HTML string after the end of the specified element.
- Use
Element.insertAdjacentHTML()
with a position of 'afterend'
to parse htmlString
and insert it after the end of el
.
const insertAfter = (el, htmlString) =>
el.insertAdjacentHTML('afterend', htmlString);
insertAfter(document.getElementById('myId'), '<p>after</p>');
More like this

Create, insert, remove and manipulate DOM elements with this collection of JavaScript tips and tricks.
Collection · 6 snippets

Inserts an HTML string before the start of the specified element.
JavaScript, Browser · Oct 20, 2020

Checks if the given element has the specified class.
JavaScript, Browser · Oct 19, 2020

Sets the value of a CSS rule for the specified HTML element.
JavaScript, Browser · Oct 22, 2020