Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 for appendChild call [duplicate]

Tags:

javascript

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?

like image 721
user5243421 Avatar asked Jul 24 '12 22:07

user5243421


1 Answers

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);
like image 152
Kristian Avatar answered Oct 13 '22 02:10

Kristian