Events are passed differently when using the inline HTML on{Event} attribute. See MDN Docs here.

When the event handler is specified as an HTML attribute, the specified code is wrapped into a function with the following parameters:

  • event — for all event handlers except onerror.

You can think of this as your code being executed within a function that already has access to the event object.

function (event) {
    handleSelect(this) // this is your script that's executing where 'this' is the DOM elem
}

You can change the handleSelect logic to use the event object instead of the passed in parameter (which in this case is the DOM element).

let handleSelect = (e) => { // e === this
    console.log(event.target.value) // event !== this 
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top