jQuery add image inside of div tag

Viewed 536594

I have a div tag

<div id="theDiv">Where is the image?</div>

I would like to add an image tag inside of the div

End result:

<div id="theDiv"><img id="theImg"  src="theImg.png" />Where is the image?</div>
7 Answers

Have you tried the following:

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

You need to read the documentation here.

this is the best way :

$(selector).prepend()

Related