Handle DOM element inserted event with DOMNodeInserted - Javascript DOM

Javascript examples for DOM:Event

Description

Handle DOM element inserted event with DOMNodeInserted

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from   ww  w .  ja v  a  2  s . c om
var container = document.getElementById('container');
container.addEventListener('DOMNodeInserted', function () {
    console.log('A node was inserted into #container');
});
var div = document.createElement('div');
div.innerHTML = 'I\'m a div!';
container.appendChild(div);
    }

      </script> 
   </head> 
   <body> 
      <div id="container"></div>  
   </body>
</html>

Related Tutorials