SomeoneS SomeoneS - 4 months ago 9x
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.


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>