Why Does The Event Handler Throws An Error In Firefox?
The following snippet works fine in the Google Chrome browser, but if I run it in Firefox it throws an error saying event is not defined. What causes this problem?
Solution 1:
The global variable event
is non-standard and Firefox does not support it.
Access the event object through the standard method (the first argument to the event handler) instead.
document.getElementById("btn").addEventListener("click", function(event) {
console.log(event.target.id)
});
<inputtype="button"id="btn"value="Click Me">
Post a Comment for "Why Does The Event Handler Throws An Error In Firefox?"