"“event” is deprecated, what should be used instead?" Code Answer


yes, the "global" event variable was never standardised broadly but was invented by microsoft and then carried on by many popular user agents ever since. it is described by whatwg to be to the event currently being processed, with an attached note:

web developers are strongly encouraged to instead rely on the event object passed to event listeners, as that will result in more portable code. this attribute is not available in workers or worklets, and is inaccurate for events dispatched in shadow trees.

the idiomatic solution to the broad class of problems your use case belongs to is to attach an event listener (on the element or its ancestor, depending), e.g with the addeventlistener function, and use the event object that is explicitly passed to the listener when it is called.

as for your concrete use case, you need to have a way to identify your figure element, since it does not have an id. for example, i will use document.queryselector("figure"):

document.queryselector("figure").addeventlistener("mousemove", zoom);

that's all, basically -- since your zoom function is already defined to work with a single argument being the actual mouse move event, it will continue working being an event listener, since it will be called with the event of interest passed as sole argument.

By James Kelleher on May 7 2022

Answers related to ““event” is deprecated, what should be used instead?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.