Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  13] [ 7]  / answers: 1 / hits: 15558  / 12 Years ago, tue, july 24, 2012, 12:00:00

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?


More From » javascript

 Answers
74

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);

[#84058] Monday, July 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristopher

Total Points: 58
Total Questions: 103
Total Answers: 102

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
;