1

Every time I click on a button <button class="xx type="submit" id="add_football">Add</button>

I want to add a image(<img src="img/door-right.png">)inside the <div class="ball_footballbox"><img src</div>

How do I do that with jQuery?

user2064285
  • 43
  • 1
  • 1
  • 6
  • 1
    This question has been answered before: the first google result for "jquery insert image into div" is http://stackoverflow.com/questions/941206/jquery-add-image-inside-of-div-tag . Not to be a dick, but please do some of your own research before posting a question. – asifrc Feb 12 '13 at 10:18
  • P.S. http://api.jquery.com/click/ and http://api.jquery.com/category/manipulation/dom-insertion-inside/ should help you learn everything you need to answer your own question. Comment/Let me know if you need some good tutorials :) – asifrc Feb 12 '13 at 10:22
  • P.P.S, In retrospect, I do come off as a dick lol (too much time has passed to edit the comment). I just wanted to let you know that it's a courtesy to do you're own research before posting a question, especially when it has been answered before, to avoid cluttering the site. I flagged this post as a duplicate to that end, nothing personal. When learning to code, Google is you're best friend (and half the time, it'll lead you right back to SO). Welcome to SO :) – asifrc Feb 12 '13 at 10:31
  • @asifrc You're not being off with the OP - this question is an exact duplicate and will *should* be deleted. – Jimbo Feb 12 '13 at 10:51

4 Answers4

4

Or $('<img src="img/door-right.png">').appendTo(".ball_footballbox");

arnaud
  • 86
  • 5
0

Try this

$(".ball_footballbox").append('<img src="img/door-right.png">');

wrap this in a function and call this function on click of button action.

Sudip Pal
  • 2,041
  • 1
  • 13
  • 16
0

try like below... it will work

HTML :

<button class="xx" type="submit" id="add_football">Add</button>
<div class="ball_footballbox"></div>

JQuery :

$("#add_football").click(function() {
$('.ball_footballbox').prepend('<img id="theImg" src="img/door-right.png" prepended="yes"/>')
});

Fiddle : http://jsfiddle.net/RYh7U/73/

Pandian
  • 8,848
  • 2
  • 23
  • 33
0

Take a look at this Demo this will help you to get the answer for adding images.

$("#add_football").click(function(){
$('<img src="http://jqfaq.com/wp-content/uploads/logo_v1.png">').appendTo($(".ball_footballbox"));
});

i hope this will help you more.

Karthi Keyan
  • 4,243
  • 5
  • 24
  • 47