Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author Gufron Rahmatain Azzain
- * required jquery library
- * Trigger function for new created DOM element
- * Usage: DOMSpawnInterceptor(YOUR_ELEMENT_CLASS_OR_ID_OR_ATTRIBUTE_NAME, YOR_CALLBACK_FUNCTION_OR_CLOSURE_FUNCTION);
- *
- * @return DOM Element object
- */
- // write less do more
- function DOMSpawnInterceptor(element, callback) {
- document.addEventListener('DOMNodeInserted', function(e) {
- if ( jQuery(e.target).is(element) ) {
- callback( jQuery(e.target) );
- }
- });
- }
- // example usage by class name
- DOMSpawnInterceptor('.foo-bar', function($this) {
- console.log('element with class name "foo-bar" created');
- });
- // example usage by element id
- DOMSpawnInterceptor('#foo-bar', function($this) {
- console.log('element with id "foo-bar" created');
- });
- // example usage by attribute
- DOMSpawnInterceptor('[your-attribute-name]', function($this) {
- console.log('element with attribute "[your-attribute-name]" created');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement