Adding images to an HTML document with javascript

I've tried some HTML DOM code from several sites, but it isn't working. It isn't adding anything. Does anyone have a working example on this?

this.img = document.createElement("img");
this.img.src = "img/eqp/"+this.apparel+"/"+this.facing+"_idle.png";
src = getElementById("gamediv");

But it isn't adding anything to the div. (gamediv) I've tried document.body as well, with no result.

Thanks in advance.


You need to use document.getElementById() in line 3.

If you try this right now in the console:

var img = document.createElement("img");
img.src = "";
var src = document.getElementById("header");
<div id="header"></div>

... you'd get this:

enter image description here