0

I am trying to debug some complex code in which some UI gets created in an iPhone phonegap application.

The problem is that it would seem that when I press the element the event handlers (that are supposedly) attached to its touchstart event don't fire.

Its either that for some reasons those events are not really attached, or the click gets blocked before reaching them somehow...

I am trying to debug this situation and was wondering:

  1. Given a jQuery object, is the a way to list the event handlers attached to it (via jQuery) for debugging purposes?

  2. Is there an easy way to override .on and have it console.log its parameters

  3. any other ideas on how I should approach such a problem

UPDATE: After validating that indeed the element has the touchstart handler and it is not being called I have discovered that if I am adding click or mousedown event handlers they do get called.

I suspect this is caused partly by jQuery mobile but I am not sure how or why and why it effects only part of my controls (those are not JQM controls...).

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
epeleg
  • 10,347
  • 17
  • 101
  • 151
  • You can get all the event handlers using `$("#id").data("events");` – Thomas Jul 23 '12 at 07:02
  • @thomas, this was a very good pointer. It allowed me to validate that an event handler for the `touchstart` event is indeed attached to my element. however still, it does not get called when I press the element on the screen of the device. any ideas on where I should go to now ? – epeleg Jul 23 '12 at 07:27
  • @thomas, do you know if this can be expressed as a selector ? i.e. select elements that have events ? – epeleg Jul 23 '12 at 07:45
  • Didn't know it but after a 10 second search: http://stackoverflow.com/questions/2891452/jquery-data-selector – Thomas Jul 23 '12 at 11:20

2 Answers2

0

This Chrome extension lists attached JQuery Events.

Nirmal Patel
  • 5,128
  • 8
  • 41
  • 52
  • this might be helpful in other scenarios. however it does not help me As my debugging is done via the phonegap remote debug console (winere). – epeleg Jul 23 '12 at 07:33
0

How do you log all events fired by an element in jQuery?

function getEventsList($obj) {
    var ev = new Array(),
        $events = $obj.data('events');
    for(var i in $events) {
        ev.push(i);
    }
    return ev.join(' ');
}

$obj.on(getEventsList($obj), function(e) {
    console.log(e);
});

I used this to find out what exact custom event was bound to an element by a jquery plugin. It gets all the attached events and calls a console.log for the event when it is fired.

Community
  • 1
  • 1
Simon
  • 7,182
  • 2
  • 26
  • 42