To list all bindings of an element with jQuery, we can use the _data
method.
For instance, if we have the following input:
<input>
Then we can write:
const input = $('input')
input.bind('click', () => {})
input.bind('input', () => {})
$.each($._data($(input)[0], 'events'), (i, e) => {
console.log(i, e);
});
to get the input with $('input')
.
Then we add the event handlers with:
input.bind('click', () => {})
input.bind('input', () => {})
Next, we get the event handler bindings with:
$._data($(input)[0], 'events')
Then we use the $.each
method to loop through the bindings returned by $._data
.
In the callback, i
is the event name string and e
has the event data,