Dave's Brain

Browse - Programming Tips - How do I remove/delete a node from the DOM using javaScript?

Date: 2010feb16
Language: javaScript
Platform: web

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); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, 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.