Reputation: 1187
I have the following structure:
<div class="eventIcons">Sample Event</div>
How do I add an tag to the div before the text so that I end up with:
<div class"eventIcons"><img id="printOnlyIcon" src"printOnly.jpg"/>Sample Events</div>
I am currently using the following jquery but its adding the tag after the text:
$('div.eventIcons').append('<img id="printOnlyIcon" src="printOnly.jpg"/>');
Many Thanks
Upvotes: 2
Views: 128
Reputation: 28763
Try like this
$('div.eventIcons').prepend('<img id="printOnlyIcon" src="printOnly.jpg"/>');
You have to prepend the imag to your div inorder to append it.
Upvotes: 0
Reputation: 79830
Use .prepend
to add element at the beginning.
See below,
$('div.eventIcons').prepend('<img id="printOnlyIcon" src="printOnly.jpg"/>');
Upvotes: 9