Keyvan M. Sadeghi
1 min readAug 26, 2019

--

Great post Andrea, thanks a lot. Is it the case that native DOM events are treated differently by the browser? Given a custom-element:

<custom-element onmyevent="console.log('myevent')">
</custom-element>

The value of document.querySelector('custom-element').onmyevent is undefined!

Whereas:

<custom-element onclick="console.log('clicked')">
</custom-element>

The value of document.querySelector('custom-element').onclick is:

ƒ onclick(event) {
console.log('clicked')
}

Is there a way to directly get a reference to onmyevent as a JavaScript object? I’m currently creating the object with .getAttribute('onmyevent') and new Function(.

--

--

Keyvan M. Sadeghi
Keyvan M. Sadeghi

Written by Keyvan M. Sadeghi

Keyvan is co-founder and CEO at Functionland, an open-source startup working on the intersection of Blockchain and AI

Responses (1)