javascript - global variable in jquery function doesn't work -
i´ve defined global variable in function, doesn't work. if define variable in function works, want global.
var currentpage = 1; $(document).ready(function(){ function checkpage(currentpage) { if (currentpage == 1) { $(".text_nav").html("some text"); }; } checkpage(); });
why want it? because want decrease variable on click something
$( "#button" ).click(function() { currentpage += 1; }); //check currentpage variable again (who?) if (currentpage == 2) { $(".text_nav").html("some other text"); };
it work, didn't send function, this:
checkpage(currentpage);
the currentpage
in function parameter, it's local variable function , separate global variable. or remove parameter if don't need it:
function checkpage() { // other 'checkpage(currentpage)' ... }
Comments
Post a Comment