+ 3
jQuery
How can I use the value of the 'a' variable outside the click function? $("btn").click(function(){ var a = 0; a++; }); now i want use value of 'a' outside of function. Please help..
3 odpowiedzi
+ 12
In most programmimg languages the variable scope exists or visible within the braces {} only.
Therefore if you want to access it from the scope outisde, then you can DECLARE it outside as well and ASSIGN it within the scope. 😉
+ 4
Hi,
u need to define ur variable where u need, and than u must define ur function like:
function(int a_) {
car a_=0;
a_++;
}
And than u can use ur function:
function(a);
Hope it's help!
+ 2
Just declare variable outside and change inside.
You're done.
var a
$("btn").click(function(){
a=0
a++
})
_________________________
or in ES6 style
let a
$('btn').click( () => {
a=0
a++
}
//any other actions with a anywhere you want