Wednesday, October 22, 2008

Remove a HTML Element using Javascript


Suppose the ID of the element is "objID"

The JavaScript method.(We are writing a custom function)



function removeElement(objID) {
var node = document.getElementById(objID);
node.parentNode.removeChild(node);
}



The JQuery method.



$("#objID").remove();



Its all about Keeping it Simple.
What do you say? :)

Related Posts :



3 comments on "Remove a HTML Element using Javascript"

Add your comment. Please don't spam!
Subscribe in a Reader
bwalton on November 20, 2010 at 4:36 AM said...

Wow.

Simply the best javascript answer I've ever seen.
Everybody else (and I mean everybody) wants to make you copy down a ton of code just to simply remove a single html element with javascript.

What if you want to remove the second parent node that will in turn include the original html element that has an ID that is targetable?

Satya Gowtham on November 22, 2011 at 4:10 PM said...

how to do it with javascript with out jquery and with out child and parent node business?

Satya Gowtham on November 22, 2011 at 4:13 PM said...

k got u here

Post a Comment