Inspect an element to investigate jQuery event bindings

前端 未结 4 1443
时光取名叫无心
时光取名叫无心 2021-01-29 19:55

Hypothetical: I find a page with a button (\'#bigButton\'), that when clicked causes a llama (\'img#theLlama\') to show() using jQuery.

So, somewhere (say, Line 76) in

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-29 20:48

    FireQuery is the most convenient, but if you need to do it manually, you can get a reference to the click handling function with $(element).data('events').click[0].handler (of course it is not necessarily 0 if there are multiple click handlers). From there it is up to your favorite debugger to locate that function in the code. (Using named functions helps. Firebug can sometimes locate anonymous functions, but more often not. It will show the body of the function though, if you hover above it with the mouse.)

    Update this is how data is shown with FireQuery:

    HTML view:

    jQuery data in Firebug HTML view

    console:

    jQuery data in Firebug console

提交回复
热议问题