Can I find events bound on an element with jQuery?

前端 未结 9 1938
南旧
南旧 2020-11-22 07:11

I bind two event handlers on this link:

Show Alert

JavaScript:

$(         


        
相关标签:
9条回答
  • 2020-11-22 07:55

    I used something like this if($._data($("a.wine-item-link")[0]).events == null) { ... do something, pretty much bind their event handlers again } to check if my element is bound to any event. It will still say undefined (null) if you have unattached all your event handlers from that element. That is the reason why I am evaluating this in an if expression.

    0 讨论(0)
  • 2020-11-22 08:01

    While this isn't exactly specific to jQuery selectors/objects, in FireFox Quantum 58.x, you can find event handlers on an element using the Dev tools:

    1. Right-click the element
    2. In the context menu, Click 'Inspect Element'
    3. If there is an 'ev' icon next to the element (yellow box), click on 'ev' icon
    4. Displays all events for that element and event handler

    0 讨论(0)
  • 2020-11-22 08:09

    General case:

    • Hit F12 to open Dev Tools
    • Click the Sources tab
    • On right-hand side, scroll down to Event Listener Breakpoints, and expand tree
    • Click on the events you want to listen for.
    • Interact with the target element, if they fire you will get a break point in the debugger

    Similarly, you can:

    • right click on the target element -> select "Inspect element"
    • Scroll down on the right side of the dev frame, at the bottom is 'event listeners'.
    • Expand the tree to see what events are attached to the element. Not sure if this works for events that are handled through bubbling (I'm guessing not)
    0 讨论(0)
提交回复
热议问题