jquery mutationobserver

Solutions on MaxInterview for jquery mutationobserver by the best coders in the world

showing results for - "jquery mutationobserver"
Dylan
30 Aug 2018
1
2// The node to be monitored
3var target = $( "#content" )[0];
4
5// Create an observer instance
6var observer = new MutationObserver(function( mutations ) {
7  mutations.forEach(function( mutation ) {
8    var newNodes = mutation.addedNodes; // DOM NodeList
9    if( newNodes !== null ) { // If there are new nodes added
10    	var $nodes = $( newNodes ); // jQuery set
11    	$nodes.each(function() {
12    		var $node = $( this );
13    		if( $node.hasClass( "message" ) ) {
14    			// do something
15    		}
16    	});
17    }
18  });    
19});
20
21// Configuration of the observer:
22var config = { 
23	attributes: true, 
24	childList: true, 
25	characterData: true 
26};
27 
28// Pass in the target node, as well as the observer options
29observer.observe(target, config);
30 
31// Later, you can stop observing
32observer.disconnect();
33
34