Run something when a DOM element appears and when it exits.
No dependencies. Legacy IE compatible. 1kb .min.gz.
Run something to initialize an element on its first appearance.
Polling for changes
$.onmount() everytime your code changes.
jQuery is optional; use it to poll on popular events. →
Supply a 2nd function to onmount() to execute something when the node is first detached. →
$documentbodyinnerHTML = ''$ //=> 'button was removed'
Onmount is available via npm and Bower.
npm install onmount bower install onmount
It can be used as a CommonJS module or on its own. It doesn't require jQuery, but if jQuery is found, it'll attach itself to it as
onmount = // With CommonJS (ie, Browserify)windowonmount // with no module loaders:$onmount // with jQuery
All modern browsers and IE8+. For legacy IE, use it with jQuery 1.x.
Examples are available in the source repo. See examples →