Dave's Brain

Browse - programming tips - javascript dom remove delete node

Date: 2010feb16
Language: javaScript

Q.  How do I remove/delete a node from the DOM using javaScript?

A.  Here's a function that does that:

function removeNode(obj) {
        var     p;

        if (obj == null) return;
        if ((p = obj.parentNode) == null) return;
        p.removeChild(obj);
}

function exampleUse() {
	var	obj;

	obj = document.getElementById('that_thing');
	removeNode(obj);
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.