In my javascript code var x=1.When some event occured, 'var x' will be incremented by 1. The updated 'x' value will be used for some other events. But the variable x value is always 1. It is because the javascript code is compiled when the page is loaded.Now, how to use the updated value in the same page for other events? Here is my code
var x=1;<br>
$(button).click(function(e){ <br>
e.preventDefault();<br>
x=x+1; <br>
});<br>
//Now,when I would like to do some other event like..<br>
$("#newdiv"+x).click(function() {<br>
alert("cliked");<br>
});<br>
I have some division with id="newdiv1" , id="newdiv2" and so on. How should differentiate the click on different divisions based on 'x' value.