javascript - Changing the global variable from inside a function, or best practice to achieve the same -
i trying change variable
called projectcounter
in jquery project don't have repeat buttons inside each div
each project. how can make change in 1 function accessible functions? have far:
var projectcounter = 1; $('a').click(function() { function setvalue() { var projectcounter = projectcounter + 1; alert(window.projectcounter); } });
i have made jsfiddle also: http://jsfiddle.net/cpfrd/
var projectcounter = 1; $('a').click(function() { setvalue();//this calls function , makes happen }); //defining/declaring function, doesn't until called function setvalue() { projectcounter = projectcounter + 1;//no var keyword because want reference existing variable, not declare new 1 alert(window.projectcounter); }
this should address problems why code not working. don't make claims best practice though.
Comments
Post a Comment