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:

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

Solution 3:

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

Solution 4:

You should concatenate the variable like this:

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

Solution 5:

Concatenating like this:

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

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