Create div and append html as its content and search added elements - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Create div and append html as its content and search added elements

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  w w  w . ja  v  a  2  s  . c om*/
var s = '@test <span class="myString">@test</span> @test2 <span class="myString">@test</span>';
var e = document.createElement("div");
e.innerHTML = s;
var spans = e.getElementsByTagName("span");
while (spans.length > 0) {
    e.removeChild(spans[0]);
}
console.log(e.innerHTML);
    }

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

Related Tutorials