jQuery add image inside of div tag

If we want to change the content of <div> tag whenever the function image()is called, we have to do like this:

Javascript

function image() {
    var img = document.createElement("IMG");
    img.src = "/images/img1.gif";
    $('#image').html(img); 
}

HTML

<div id="image"></div>
<div><a href="javascript:image();">First Image</a></div>

Have you tried the following:

$('#theDiv').prepend('<img id="theImg" src="theImg.png" />')

my 2 cents:

$('#theDiv').prepend($('<img>',{id:'theImg',src:'theImg.png'}))

$("#theDiv").append("<img id='theImg' src='theImg.png'/>");

You need to read the documentation here.

Tags:

Jquery