Spye
Detect when a DOM element is created or removed.
Installation
Node.js
npm install spye --save
Browser
Local
CDN unpkg
Example
const Spye = ; '#my-element' ; // Create and append element to bodylet element = document;element;documentbody; // Remove element after 1s;
API
Spye
Kind: global class
new Spye(query, [opts])
Create instance
Param | Type | Default | Description |
---|---|---|---|
query | Object | element that you want watch |
|
[opts] | Object | configuration object |
|
[opts.autoWatch] | boolean | true | auto watch |
[opts.checkMs] | number | 50 | interval in milliseconds for every check |
[opts.unwatchAfterCreate] | boolean | false | stop check after detect element creation |
[opts.unwatchAfterRemove] | boolean | false | stop check after detect element remove |
Spye
spye.watch() ⇒ Start watching
Kind: instance method of Spye
Spye
spye.unwatch() ⇒ Stop watching
Kind: instance method of Spye
Spye
spye.onCreate(callback) ⇒ Fired when element is created
Kind: instance method of Spye
Param |
---|
callback |
Spye
spye.onRemove(callback) ⇒ Fired when element is removed
Kind: instance method of Spye
Param |
---|
callback |
Changelog
You can view the changelog here
License
Spye is open-sourced software licensed under the MIT license