I'm surprised to find this code in the example:
- $( document ).on( "pageinit", "#demo-page", function() {
-
- $( document ).on( "swipeleft swiperight", "#demo-page", function( e ) {
The way this is written, the
pageinit is actually completely irrelevant and unnecessary.
As well, this will redundantly re-register the delegation every time the page is initialized.
I would do it like this (and would never use an ID, so you will see a class for the page)
- $(document).on("pageinit", ".demo-page", function() {
- var $page = $(this);
- $page.on("swipeleft swiperight", function(e) {
You could also just do it like this:
- $(document).on("swipeleft swiperight", ".demo-page", function(e) {
However, this is less efficient, as the event will always have to bubble-up all the way to the document, where in my first example, it only bubbles to the page.