dom-insert

DOM insertion methods.

Usage no npm install needed!

<script type="module">
  import domInsert from 'https://cdn.skypack.dev/dom-insert';
</script>

README

dom-insert

Build Status

DOM insertion methods.

Installation

npm install dom-insert

API

Available methods:

  • after(element, content): insert content after.
  • before(element, content): insert content before.
  • append(element, content): append content to.
  • prepend(element, content): prepend content to.

Each method accepts:

  • element {Element}: DOM element
  • content {String|Node|NodeList|Array}: the HTML string, Node, or Node collection to insert.

Examples

var domInsert = require('dom-insert');
var foo = document.querySelector('.foo');

domInsert.after(foo, '<div>After foo</div>');
domInsert.before(foo, document.querySelectorAll('.bar'));
domInsert.append(foo, document.querySelector('.bar'));
domInsert.prepend(foo, [ document.createElement('div'), document.createElement('div') ]);

Browser support

  • Google Chrome
  • Firefox
  • Internet Explorer 9+
  • Safari
  • Opera