0

I am trying to add a class/id with a number each time a generate a new div element. Using jQuery UI dialog to add title + content for my block

Eg: add element function {

if there is no div = <div id="block0">

else = count blocks = <div id="block[i]">

Tried with

$('#' + div).prepend(function (i) {
    i = 'block' + (i + 1);
}

but is adding same number each time.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Adrian
  • 491
  • 6
  • 23
  • 1
    http://stackoverflow.com/questions/18975990/dynamically-creating-div-using-javascript-jquery – Nagaraj S Mar 16 '17 at 09:40
  • Please don't do this. Incremental `id` attributes is an anti pattern. Group elements using common class names and use DOM traversal to find related elements. – Rory McCrossan Mar 16 '17 at 09:43
  • @NagarajS In container I have other div's too. So not all of them are dynamically generated and not all of them save numeric class. – Adrian Mar 16 '17 at 09:43

0 Answers0