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? :)
3 comments on "Remove a HTML Element using Javascript"
Subscribe in a Reader
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?
how to do it with javascript with out jquery and with out child and parent node business?
k got u here
Post a Comment