faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

33 of 38 people (87%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

Is there a way to remove HTML elements from a file? What is the opposite of insertAdjacentHTML?

Oct 3rd, 2001 02:42
Martin Honnen, Himanshu Tayal,


The method insertAdjacentHTML is part of the IE4 DOM, with IE4+ to 
delete content from the document you set the outerHTML or innerHTML or 
outerText or innerText of an element, for instance if you have
  <div id="aDiv">Kibology</div>
you can remove the content of the div by setting
  document.all.aDiv.innerText = '';
You can remove the complete div by setting
  document.all.aDiv.outerText = '';
Of course if you want to replace content you can simply change one of 
the properties e.g
  document.all.aDiv.outerHTML = 
   '<input type="button" onclick="alert(\'Kibology\')" value="button">';
As for other browsers like IE5+ and NN6 which implement the W3C DOM 
methods to manipulate the document there you use methods like 
removeChild or replaceChild for instance to remove the above div 
completely
  var div = document.getElementById('aDiv');
  div.parentNode.removeChild(div);