Ravichandran Jothi Ravichandran Jothi - 3 months ago 12
jQuery Question

How to add a div when clicking a button in jquery?

I need to add the following div structure when i click button at every time?
I need to generate the following whole div structure at every time of clicking the button using jquery.

<div class="module_holder">
<div class="module_item">
<img src="images/i-5.png" alt="Sweep Stakes"><br>sendSMS
</div>
</div>


help me.

Thanks
Ravi

Answer

You need a container div that you can insert it into:

<div id="container"></div>

Then you can use the append() method of jquery:

$("#somebutton").click(function () {
  $("#container").append('<div class="module_holder"><div class="module_item"><img src="images/i-5.png" alt="Sweep Stakes"><br>sendSMS</div></div>');
});
Comments