Javascript: Creating self-closing img tag?

Tarzan

New Member
I'm trying to dynamically create an img tag with the "createElement" function.
However the result comes out like this:
Code:
<img src="target" alt="noimage">
but of course, I would like the tag to be closed:
Code:
<img src="target" alt="noimage" />

Is this possible to do with createElement? Or is there another function I should use?
 

leroy30

New Member
Hmm I'm not sure but you could just do something like this...

document.getElementById(parentElement).innerHTML = "<img src="target" alt="noimage" />";
 
Top