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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -