2

I have a listview click event: http://jsfiddle.net/w2JZU/260/

$('#todayvalue').children('li').on('click', function () {
    var selected_index = $(this).attr('id');
    alert('Selected Index = ' + selected_index);
});​

This method works well on jquery mobile. But when I deploy it onto PhoneGap javascript files, this error would show up.

mu is too short
  • 426,620
  • 70
  • 833
  • 800
Yang
  • 6,682
  • 20
  • 64
  • 96

2 Answers2

6

on was introduced to JQuery in v1.7, Nov 2011. It is not yet in JQuery Mobile.

000
  • 26,951
  • 10
  • 71
  • 101
0

Try

$('#todayvalue').children('li').click(function () {
var selected_index = $(this).attr('id');
alert('Selected Index = ' + selected_index);
});​

.on might not be available on your version of jQuery mobile.

sjobe
  • 2,817
  • 3
  • 24
  • 32
  • 1
    Newer versions of jQuery have [`on`](http://api.jquery.com/on/) as a replacement for `bind`, `live`, and `delegate`. – mu is too short Apr 13 '12 at 01:59
  • 5
    'On' is perfectly acceptable. In fact, it is provides additional functionality than .click. It depends on what the OP is trying to do... this may work for them. – John Green Apr 13 '12 at 01:59
  • this event won't fire on Phonegap. It works fine for jquerymobile. – Yang Apr 13 '12 at 03:49
  • 2
    Using click() instead of on('click',...) fixed it for me ; I'm using Phonegap/Cordova and Jquery Mobile. Thanks @sjobe . – Max Jun 12 '12 at 13:18
  • Using bind() instead of on() is also an alternative (see this answer : http://stackoverflow.com/a/10912370/189687 ) – Max Jun 12 '12 at 13:23