How do I create and append an image with Javascript/jQuery?
- by Chris Armstrong
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?