i have variable “count” in javascript. function click(e){ var count=0; } i need to assign this count variable uniquely to every label.<label id="1" onclick="click(this)>a</label> <label id="2" onclick=click(this)>b</label>
when i click the label it would call function click(). there the count variable should not be global. the count variable for label id=1 call should different value to that of label id=2 call.
ie label1.count=1
label2.count=2;
is there any way to do like this?????
The easy way is to set an arbitrary property on the HTML element. This is cross-browser, although it’s not part of any standard AFAIK.
If you just want to know whether or not it has been clicked in some kind of toggle fashion, you could set a boolean attribute:
If you are willing to use jQuery, it can be slightly more beautiful, using the
datamethod: