Ravichandran Jothi Ravichandran Jothi - 1 year ago 74
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

help me.


Answer Source

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>');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download