Skip to content Skip to sidebar Skip to footer

How Can I Set The Value Of A Variable As An ID In Jquery

Given the following code: var counter = 0; //counter variable $('#divfuerimage').on('click', function(evt){ counter= counter+1; //count up alert(counter); var conta

Solution 1:

concatenate the string or create an element like this.

$('<div>',{
   "class":"child",
   "id": counter
});

Solution 2:

Try this:

$('<div class="child" id="'+counter+'"></div>')

Solution 3:

$('<div class="child" id="'+counter+'"></div>')

Solution 4:

You should concatenate the variable like this:

$('<div class="child" id="'+coutner+'"></div>')

Solution 5:

Concatenating like this:

$('<div class="child" id='+counter+'></div>')

Post a Comment for "How Can I Set The Value Of A Variable As An ID In Jquery"