Set Dynamic Id using JS using Counter

317 Views Asked by At

I am trying to dynamically set a cell id using a cnt counter variable. However, instead of a number, I get the cnt word when viewing page source in browser.

What is wrong

 q1TargetVolume.setAttribute('id', `q1TargetVolume-${cnt}`);  
1

There are 1 best solutions below

3
On BEST ANSWER

I guess you wish to append a count value to the string q1TargetVolume-, and use it as the id for an element. You can try this method.

q1TargetVolume.setAttribute( 'id', 'q1TargetVolume-' + cnt );//cnt is the count value you wish to append