remove element by tag name using javascript

<html>
 <head>
  <title>remove element by tag name using javascript</title>
 </head>
 <body style="background:lightgray">
  <p>Click the button to test:</p>
  <button onclick="test()">remove p element</button>
  </br>
  <textarea id="edit" style="height:200px;width:240px">
   <body>
    <p>hello world<span>!</span></p>
   </body>
  </textarea>
  <script>
  function test() {
   var el = document.createElement( 'html' );
   var edit= document.getElementById("edit");
   el.innerHTML =edit.value;
   removeElementByTagName(el,"p");
   edit.value=el.innerHTML;
  }
  function removeElementByTagName(el,tagName) {
   var elements=el.getElementsByTagName( tagName );
   while (elements[0]) elements[0].parentNode.removeChild(elements[0]);
  }
  </script>
 </body>
</html>

Comments

Popular posts from this blog

How to write data into a excel file using vbscript

Format date as yyyy-mm-dd using vbscript