I am currently working on a website. What I want it to do is when you load the page a countdown starts, and after 15 seconds a button appears.
Currently it works perfectly on my test server, and on jsFiddle. However when I move it to my web server it doesn't work. I took a look in Google Chrome's Console, and I get the following error.
downloadButton.parentNode.replaceChild(newElement, downloadButton);
Uncaught TypeError: Cannot read property 'parentNode' of null
Here is the full code (See also jsFiddle http://jsfiddle.net/6zchq/)
var downloadButton = document.getElementById('download');
var counter = 15;
var newElement = document.createElement('p');
newElement.innerHTML = 'Getting your file, please wait 15 seconds.';
var id;
downloadButton.parentNode.replaceChild(newElement, downloadButton);
id = setInterval(function() {
counter--;
if(counter < 0) {
newElement.parentNode.replaceChild(downloadButton, newElement);
clearInterval(id);
} else {
newElement.innerHTML = "Getting your file, please wait " + counter.toString() + " seconds.";
}
}, 1000);
I'm sure this is a simple problem, I just cannot figure out why it's not working.
Any help is appreciated!
Thanks.