javascript - Get all events handlers attached to an element -
i need find events handlers attached #myselect , if event created via jquery can , here alert(e) show "change" without "click"
javascript :
$("#myselect").change(function(){ alert("changed"); }) $.each($._data( $("#myselect")[0], "events" ), function(e) { alert(e); })
html :
<select id="myselect" onclick="alert('hello')" > <option value="1">option 1</option> <option value="2">option 2</option> <option value="3">option 3</option> <option value="4">option 4</option> </select>
the short answer it's not possible reliably determine listeners on element using javascript.
the long answer there no standard mechanism list attached listeners. libraries keep list of listeners have been attached using library, don't know other listeners. listeners added in markup or element properties can found testing related element properties , attributes (somewhat tedious testing onclick, onchange, onblur, etc. each element). it's impossible find listener added using addeventlistener or attachevent unless reference has been kept somewhere , it's made available (see comment libraries).
also, there "delegated" listeners give appearance of being attached element when in fact attached parent element.
Comments
Post a Comment