Lee Lee - 3 months ago 6
jQuery Question

how to add counter to a class name in jquery

<!--javascript-->
$('.balance'+i).attr({someattr....});
//if thats correct OR
$('.balance'+i+'').attr({someattr....});




I was wondering how can i add a counter to a class name in jquery like the above

Answer

It does not make any difference. In the second example you just concatenate an empty string to your class string. So both results in the same string. The following statement is true: '.balance'+i == '.balance'+i+''.

Since you does not need the second concatenation I would suggest using the first option: '.balance'+i.

Hint: You have used {} instead of () (but I think you just made a typo), so your example results in a syntax error. Correct would be: $('.balance'+i).attr();

Comments