Insert element before an element inside DOM - Javascript DOM

Javascript examples for DOM:Document createElement

Description

Insert element before an element inside DOM

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title>JS</title> 
   </head> 
   <body> 
      <script type="text/javascript">
            var//from  w w w . j av a 2  s  .com
                scriptElement,
                script;
            scriptElement = document.createElement('script');
            scriptElement.src = "https://code.jquery.com/jquery-2.2.2.min.js";
            script = document.getElementsByTagName('script')[0];
            script.parentNode.insertBefore(scriptElement, script);
        
      </script>  
   </body>
</html>

Related Tutorials