Let,
<span onclick="foo()" onfocus="goo()">Have Event</span>
Here I give this just for example. Here with the span two events have bind.
Is there any javascript or jquery way to find out all events bind with any html element?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t with DOM2-style event handlers (ones added with
addEventListener/attachEvent), which pretty much means you don’t want to be doing this as DOM2+ handlers are increasingly The Way It Shall Be Done(tm).The ones you’ve shown in your example are DOM0 event handlers, though, which you can check for:
You can loop through the properties on the element, looking at the ones starting with “on”, and see whether they have a value:Update:
Apparently, at least on Chrome, the
onXyzproperties are non-enumerable so they don’t show up infor..inloops. And on Firefox, you only see the ones assigned programmatically, not via attributes.So, you can test them explicitly:
…but you’ll have to have a list of the ones you want to know about.
Here’s an example (live copy):
HTML:
JavaScript:
Note again, though, that you probably don’t want to do this, as you’ll miss DOM2+ handlers.
Also note that an event may be handled when you click an element even though that element doesn’t have an event handler for the event — because the event can bubble to the parent, which looks at the
event.target, sees the relevant child, and takes appropriate action. This is how event delegation works, and it too is increasingly The Way It Shall Be Done(tm), so… 🙂