SomeoneS SomeoneS - 1 year ago 69
jQuery Question

Creating divs with different id's

i have one question regarding creation of divs:

I have button, when user clicks on it, javascript (or jquery) needs to create a div. But when user clicks again, it should create another div, but with different id. So, every time user clicks should be created div with different id.

I partialy know how to create div, but i have no idea how to make divs with different id's.

Answer Source

var c = 0; // Counter

$('#add').on('click', function() {
  c += 1;
  $('#parent').append('<div id="child'+ c +'">'+ c +'</div>');
<script src=""></script>
<button id="add">ADD</button>
<div id="parent"></div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download