Possible Duplicate:
javascript appendChild doesn't work
The error occurs on the last line of this snippet:
var anchor = "<a id=\"hostname\" href=\"" + destination + "\"> "+ imagename + "</a>";
var specialdiv = document.getElementById("specialdiv");
console.log("div: " + specialdiv);
specialdiv.appendChild(anchor);
There's really nothing else going on... I verified that specialdiv
isn't null or something like that. Can anyone explain why I'm getting this error on that line?
don't pass a string, but an element
var link = document.createElement('a');
link.innerHTML = imagename;
link.id = "hostname";
link.href = destination;
var specialdiv = document.getElementById("specialdiv");
specialdiv.appendChild(link);
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