jquery/jquery-mobile — Issue #3645: using on()/off() #pageID with JQM1.unstable and jquery 1.7+
Author: frequent
Created: 2012-02-26 10:31:32+00:00
State: open

Maybe a little early, but I tried out the new on()/off() binding with the JQM 1.unstable and Jquery 1.7.1 (from jqm/test/docs)

Turns out I can only use the new bindings like this:

$('div:jqmData(role="page")').on('pageshow', function() { /* do stuff */ });

This doesn't seem to work:

$('#pageID').on('pageshow', function() { /* do stuff */ });

In a multipage-page this will fire once per page, so any handlers I'm trying to attach inside the on()-binding will be attached multiple times.

I'm using this to workaround:

$('div:jqmData(role="page")').on('pageshow', function() {
console.log("per page");
if ( $('.button').length > 0 && $('.button').jqmData('bound') != true) {
console.log("once");
$('.button').jqmData('bound',true);
$('.button').on('click', function() {
console.log("click attached");
});
}
});