OK, you basically don't need to know the parent to delete a DOM element from DOM, look at the below code, see how is the order to delete a node element in JavaScript:
Element
+ parentNode
+ removeChild(Element);
As you see we find the element first, then using .parentNode and then remove the child which is the Element again, so we don't need to know the parent at all!
So now look the real code:
var navigation = document.getElementById('navigation');
if(navigation) {
navigation.parentNode.removeChild(navigation);
}
or as a function
function removeNode(element) {
if(element) { //check if it's not null
element.parentNode.removeChild(element);
}
} //call it like : removeNode(document.getElementById('navigation'));
Also jQuery has remove() function which is widely use, like:
$('#navigation').remove();
Also there is native ChildNode.remove()
which is not in IE and old browsers, but you can polyfill it, look the suggested polyfill from MDN:
Polyfill
You can polyfill the remove() method in Internet Explorer 9 and higher
with the following code:
//from:https://github.com/jserz/js_piece/blob/master/DOM/ChildNode/remove()/remove().md
(function (arr) {
arr.forEach(function (item) {
if (item.hasOwnProperty('remove')) {
return;
}
Object.defineProperty(item, 'remove', {
configurable: true,
enumerable: true,
writable: true,
value: function remove() {
this.parentNode.removeChild(this);
}
});
});
})([Element.prototype, CharacterData.prototype, DocumentType.prototype]);
If you like to learn more about it, visit this link on MDN.