CS601 – Delete Current Element from DOM

At one point a few weeks back (for one of the homeworks), I could not figure out how to delete the current element from the DOM while working in Javascript. Some searching turned up the following solution:

detaildiv.parentNode.removeChild(detaildiv);

Basically, you get the element’s parent node, then deleted the specified child node, this being the element. I’m not sure this the standard method, but it works and is clean. (This was before we were looking at JQuery, so perhaps it has a better solution.)

One thought on “CS601 – Delete Current Element from DOM

Leave a Reply

Your email address will not be published.