I know that I can access a mouse event if I assign the mouse listener with js:
myElement.addEventListener("click", e => console.log(e.pageX))
My question is: is it possible to access the mouse event when assigning the listener by html attribute?
<div onclick="alert('where is the mouse event?')"></div>
The onclick will be evaluated as the inside of a function, and that function will have an argument of the event, so you can do it like this:
<div onclick="console.log(arguments[0].pageX)">text</div>
But you really, really shouldn't. Always attach listeners with Javascript instead of HTML-inline-eval. Code will be easier to write, easier to read, safer, and more maintainable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With