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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -