There are three popular methods for connecting events to DOM nodes.
The addEventListener()
function is used to register event listeners following the W3C DOM standards. While it has numerous advantages, it is not compatible with Internet Explorer. To work with Internet Explorer, you must utilize the attachEvent()
method, which provides similar capabilities.
Conversely, the onclick
property is an older but more universally supported approach for attaching event handlers. However, it does have limitations, such as only permitting one event handler per event.
Regarding retrieving the event handlers linked to a specific node, it varies depending on the method employed to attach the events. The issue in your scenario arises from using the addEventListener()
method to connect the event and then attempting to access it through the onclick
property.
For further insights on this subject, especially the perspective shared by @Crescent Fresh, I recommend checking out the following Stack Overflow discussion:
- How to find event listeners on a DOM node?