1.0.2 • Published 1 year ago

@egn/dom v1.0.2

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

These DOM methods are supported by all major browsers, including IE 8 and below.

If you intend to insert a new structure in form of an HTML text string, you should make use of insertAdjacentHTML(). This method parses the specified text as HTML and inserts the resulting elements into the DOM tree at a specified position. It does not reparse the element it is being used on and thus it does not corrupt the existing elements inside the element.

Basic usage

const { insertAfter } = require('@egn/dom');

// example

// New element as newEl
const newEl = document.createElement('div');
newEl.innerHTML = '<p>Hello World!</p>';

// Existing element as ref
var ref = document.querySelector('div.before');

insertAfter(newEl, ref);

Usage Options

  • insertAfter() lets you insert a new element after an existing one in the DOM tree.
  • insertBefore() lets you insert an element before another one.