×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Jing Tai Piao
Added: Jan 15, 2014 1:44 AM
Views: 4
Tags: no tags
  1. var observeDOM = (function(){
  2.   var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
  3.       eventListenerSupported = window.addEventListener;
  4.  
  5.   return function(obj, callback){
  6.       if( MutationObserver ){
  7.           // define a new observer
  8.           var obs = new MutationObserver(function(mutations, observer){
  9.               if( mutations[0].addedNodes.length || mutations[0].removedNodes.length )
  10.                   callback(obj);
  11.           });
  12.           // have the observer observe foo for changes in children
  13.           obs.observe( obj, { childList:true, subtree:true });
  14.       }
  15.    
  16.       else if( eventListenerSupported ){
  17.           obj.addEventListener('DOMNodeInsertedIntoDocument', callback(obj), false);
  18.          // obj.addEventListener('DOMNodeRemoved', callback, false);
  19.       }
  20.   }
  21. })();
  22.  
  23. observeDOM( document ,function(obj){
  24.   console.log($('table'));
  25.   console.log(obj);
  26.   if($('table').table_name == 'jobseeker_list'){
  27.     alert('hahah');
  28.     obj.removeEventListener('DOMNodeInsertedIntoDocument');
  29.   }
  30. });