You are getting that error because appendChild
takes DOM elements, not strings. You need to actually create a DOM element before using appendChild
.
var anchor = document.createElement('a');
anchor.id = "hostname";
anchor.href = destination;
anchor.innerHTML = imagename;
var specialdiv = document.getElementById("specialdiv");
specialdiv.appendChild(anchor);