Process dynamic html string with dom method by adding it to innerHTML - Javascript DOM

Javascript examples for DOM:Element innerHTML

Description

Process dynamic html string with dom method by adding it to innerHTML

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 www  . jav  a2  s. c  o  m*/
var htmlString = "<html><body><div class='class'>test!</div></body></html>"
var htmlElem = document.createElement("html");
htmlElem.innerHTML = htmlString;

console.log(htmlElem.getElementsByClassName("class")[0].innerHTML);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials