I am trying to delete a hidden element. I have tried the following codes but it always returns the parent as undefined.
attempt one
var timeLeft = document.getElementById("time");
timeLeft.document.removeChild(timeLeft);
attempt two
var timeLeftBody, timeLeft;
timeLeftBody = document.getElementsByTagName("body")[0];
timeLeft = document.getElementById("time");
timeLeft.timeLeftBody.removeChild(timeLeft);
removeChild() only works on an element that directly contains the child -- document.removeChild(hdr) won't work unless the document directly contains the time element (which is impossible, unless time is the html node).
Try:
var timeLeft = document.getElementById("time");
timeLeft.parentNode.removeChild(timeLeft);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With