Created
September 30, 2022 10:34
-
-
Save angelikatyborska/dc846d79eb1b0eec4a1b163154ed0857 to your computer and use it in GitHub Desktop.
Add event listeners to all possible events on an element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
element = ... | |
listener = ... | |
for (const key in element) { | |
if(/^on/.test(key)) { | |
const eventType = key.substr(2); | |
element.addEventListener(eventType, listener); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment