nanoonload
v0.6.0
Published
tiny wrapper around mutation observe to detect added and removed elements
Downloads
5
Readme
nanoonload
tiny wrapper around mutation observe to detect added and removed elements
how to get
install from npm
npm i nanoonload
how to use
example, using body
const nanoonload = require('nanoonload');
const el = document.createElement('div');
el.className = 'test1';
el.textContent = 'addElement';
nanoonload('div.test1', // can also be a nodeElement
(el) => { console.log('element is added'); },
(el) => { console.log('element is removed'); }
);
document.body.appendChild(el);
document.body.removeChild(el);
example, with a targetNode
const nanoonload = require('nanoonload');
const baseElement = document.createElement('div');
baseElement.className = 'baseElement';
const appendEl = document.createElement('div');
appendEl.className = 'addElement';
nanoonload('div.addElement',
(el) => { console.log('element is added'); },
(el) => { console.log('element is removed'); }, {
targetNode: baseElement
}
);
baseElement.appendChild(appendEl);
baseElement.removeChild(appendEl);