domy-insert

Insert any data type to the DOM

domy-insert

Insert any data type to the DOM. For use with Browserify.

Part of the Domy module collection.

npm install domy-insert --save
var insert = require('domy-insert');
 
insert('<div class="item"></div>').after('.some-parent-element');
insert('<div class="before-item"></div>').before('.item');
 
var div = document.createElement('div');
div.className = 'another-element';
 
insert(div).beginning('.parent');
 
insert(div).end() // inserted at end of document.body 
  • element - string OR DOM element to insert

Creates and returns an object with the following methods available:

  • before
  • after
  • beginnning
  • end
  • sibling - string or object of element to insert before
  • parent - string or DOM element of context of insert. Defaults to document.body
  • sibling - string or object of element to insert after
  • parent - string or DOM element of context of insert. Defaults to document.body

Insert an element at the beginning of the given parent's child node list

  • parent - string or DOM element of context of insert. Defaults to document.body

Works the same as insert(element, parent). Inserts element at the end of the given element context

  • parent - string or DOM element of context of insert. Defaults to document.body
npm install
npm test