How do I create and append an image with Javascript/jQuery?
Posted
by
Chris Armstrong
on Stack Overflow
See other posts from Stack Overflow
or by Chris Armstrong
Published on 2011-02-19T14:48:40Z
Indexed on
2011/02/19
15:25 UTC
Read the original article
Hit count: 248
I'm using the following code to create an image element, load it, then append it to the article on load.
$('<img />')
.attr('src', 'image.png') //actually imageData[0].url
.load(function(){
$('article').append( $(this) );
alert('image added');
});
The alert is firing off ok, but the image doesn't appear, and when I inspect the element it has been added without the closing slash
<img src='image.png' >
Why is the browser removing the forward slash and how do I stop it?
© Stack Overflow or respective owner