var attrs = $('input').get(0).attributes;
var f = Array.prototype.filter.call(attrs, isEvent); //Filter all attributes
//f now contains all attribute nodes that are events
f.forEach(function(e) { console.log(e.nodeName); });
function isEvent(element) {
return element.nodeName.startsWith('on');
}
For the following input markup, it would log onclick, onchange. Works for events that are attached inline or event attributes created with JavaScript.
<input name='student' onclick='show()' onchange='return true;'/>
Or
var el = $('input').get(0);
el.setAttribute('onkeyup', function() {});
getEventsFor(el).forEach(function(e) {
console.log(e.nodeName); //onSomeEvent
console.log(e.nodeValue); // attached handler
});
function isEvent(element) {
return element.nodeName.startsWith('on');
}
function getEventsFor(element) {
var attrs = element.attributes;
return Array.prototype.filter.call(attrs, isEvent);
}
JSFiddle
"<"input name='student' onclick='show()'">"Why did you put quotes like in your code? Is it string or what? This doesn't seem correct.