Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

nanoonload

0.6.0 • Public • Published

nanoonload

tiny wrapper around mutation observe to detect added and removed elements

Join the chat at https://gitter.im/moszeed/nanoonload

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);

Install

npm i nanoonload

DownloadsWeekly Downloads

2

Version

0.6.0

License

MIT

Unpacked Size

6.45 kB

Total Files

6

Last publish

Collaborators

  • avatar