In JavaScript DOM, can it be determined if an element will listen for an event type? [duplicate]
Possible Duplicate:
Detecting support for a given JavaScript event?
having a random HTMLElement el
, is开发者_运维问答 there anyway of knowing whether el
can listen to an particular event type, for example, 'change'?
you can try checking if el.attributes.onchange
is declared. I'm not sure, however, if dynamic changes to the webpage will be visible in this manner.
Yes, you can check it for a truthy value like this:
if (el.change) {
el.change();
}
If the method exists you will be able to call it like this. You can check for any method in the manor before trying to call it.
精彩评论