tags:

views:

8278

answers:

2

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>
+14  A: 

Have you tried the following:

$('#theDiv').prepend('<img id="theImg" src="theImg.png" />')
Topher Fangio
I can't respond to Jose Basilio above (not enough rep) but append will put it AFTER "Where is the image?". Prepend will put it before.
Topher Fangio
I was about to upvote you for using prepend, but I noticed that you're missing '#' in your selector...
Ben Koehler
+1 for prepend :)
fmsf
Danget! I do that all the time. Thanks for catching that :-)
Topher Fangio
I jumped the gun with append. Good catch. +1
Jose Basilio
Thanks worked like a charm :)
Phill Pafford
appendTo doesn't work...at least in my code and it wasn't the right one to use after I read it on the jQuery docs page even before posting this thread.
CoffeeAddict
A: 
$("#theDiv").append("<img id='theImg' src='theImg.png'/>");

You need to read the documentation here.

jacobangel
Borgenk