Plain JavaScript - Manipulating DOM Elements

Adding, removing, copying DOM elements and related manipulations.


Replace a DOM element

Remove an element from the DOM tree and insert a new one in its place.

jQuery: $.replaceAll(), $.replaceWith()

Unwrap a DOM element

Remove the parents of an element from the DOM, leaving the element's content in place.

jQuery: $.unwrap()

Append or prepend to an element

Insert a new element or an HTML structure to the end or the beginning of another element's content.

jQuery: $.append(), $.appendTo(), $.prepend(), $.prependTo()