javascript - Appending an image to a div, but the image is called null -
if change document.body.appendchild(timg) document.div.appendchild(timg)
, error saying cant appendchild of null. function happens inside initialize.
function placefighter(t, imagefile) { timg = document.createelement("img"); timg.src = imagefile; timg.tangible = t; playerimg.push(timg); document.body.appendchild(timg); }
i'd add id div , change code this.
function placefighter(t, imagefile){ var timg = document.createelement("img"); timg.src = imagefile; timg.tangible = t; playerimg.push(timg); document.getelementbyid('mydiv').appendchild(timg); }
Comments
Post a Comment