Finding bounded events in inspector

北战南征 提交于 2020-01-05 21:16:40

问题


I've been wondering a long time about this. Is there a way in eg Chrome to see what events are bound to an element? Since many people now use jQuery with a syntax like the following:

$("a.subtle").click(function(){
    //do something
});

Is there a way in the inspector to easily find this code? I know in the inspector you can go to the "event listeners"-tab to see what events are bound. Looking at an example I can see there is a click-event on the element with the js file of jQuery next to it, so this must somehow point to it, but of course it is obscured by all the jQuery code. Here's what I'm looking at:

So the question is, is there a quick way to find the jQuery code applied to an element? To be clear, I want to quickly find the code I posted up top.

I could search through the source code for a .click() on that class, but of course it could be done via its parent, or with .on(), or on so many bazillion ways..


回答1:


Check out the Visual Event bookmarklet.


Here's a quote from their website:

Visual Event is an open source Javascript bookmarklet which provides debugging information about events that have been attached to DOM elements.

Visual Event shows:

  • Which elements have events attached to them.
  • The type of events attached to an element.
  • The code that will be run with [sic] the event is triggered.
  • The source file and line number for where the attached function was defined (Webkit browsers and Opera only).


来源:https://stackoverflow.com/questions/18561546/finding-bounded-events-in-inspector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!