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
To display or hide a <div> by a <button> click, you can add the onclick event listener to the <button> element. The onclick listener for the button will have a function that will change the display attribute of the <div> from the default value (which is block ) to none .
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>');
});
Try this out http://jsfiddle.net/4dEsJ/1/ I'm sure there are better ways of creating the element, but if the structure and content remains the same, this works!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With