Possible Duplicate:
Why does removeChild need a parent node?
Cross-browsers way to remove a node element is to use removeChild()
method.
However, this way expects us to precise the node's parent as follows:
myNodeToRemove.parentNode.removeChild(myNodeToRemove);
Why didn't browsers implement the remove method with a more object-oriented way like this:
myNodeToRemove.remove();
With remove()
method starting as follows:
function remove(){
var parentNode = this.parentNode;
....
}
Indeed, using this way, no need to manually get the node's parent.