jeudi 1 juillet 2021

How to set a checkbox handler that uses "this" parameter in Typescript?

In HTML I can write:

<input type="checkbox" id="MyBox" onchange="MyHandler(this.checked)">

Instead of specifying the handler in HTML, I want to set it TypeScript. I tried:

document.getElementById('MyBox').onchange = function(){MyHandler(this.checked); };

but get the error "Property 'checked' does not exist on type 'GlobalEventHandlers'". How do you then access the attributes of "this"?




Aucun commentaire:

Enregistrer un commentaire