Hi all I seem to be having a problem with my jQuery mobile script.
<script>
$(document).bind('pageinit', function()
{
var count=0;
var pages = ["#home","#rich","#dan"];
$('.master').click(function()
{
count=count+1;
$.mobile.changePage($(pages[count]));
console.log(count);
});
});
</script>
So what will happen is on first click it works. Count goes up to 1 and the page changes to #rich. Second click the count goes to 2 the page flashes real quick to #dan and then flashes right back to #rich and the count goes back down to 1. If i click again i get an error saying
b.data(“page”) is undefined
No idea why. Any help?
As Huangism suggested, pageinit is run every time a new page is loaded, most likely resetting your counter. Try setting up your click event using $(document).ready() or some other event that only fires once.