spye
v0.0.5
Published
Detect when a DOM element is created or removed
Downloads
8
Maintainers
Readme
Spye
Detect when a DOM element is created or removed.
Installation
Node.js
npm install spye --save
Browser
Local
<script src="node_modules/spye/dist/spye.min.js"></script>
CDN unpkg
<script src="https://unpkg.com/spye/dist/spye.min.js"></script>
Example
const Spye = require('spye');
new Spye('#my-element')
.onCreate((element)=> console.log('created', element))
.onRemove(()=> console.log('removed'));
// Create and append element to body
let element = document.createElement('div');
element.setAttribute('id', 'my-element');
document.body.appendChild(element);
// Remove element after 1s
setTimeout(()=>{
document.body.removeChild(element);
}, 1000);
API
Spye
Kind: global class
new Spye(query, [opts])
Create instance
spye.watch() ⇒ Spye
Start watching
Kind: instance method of Spye
spye.unwatch() ⇒ Spye
Stop watching
Kind: instance method of Spye
spye.onCreate(callback) ⇒ Spye
Fired when element is created
Kind: instance method of Spye
spye.onRemove(callback) ⇒ Spye
Fired when element is removed
Kind: instance method of Spye
Changelog
You can view the changelog here
License
Spye is open-sourced software licensed under the MIT license
Author
Fabio Ricali