There is a <input type="checkbox" id="mainCheckbox" />
,I want to use the property checked
of it.And the vscode waring Property 'checked' does not exist on type 'HTMLElement'
.I know that must be type HTMLInputElement
,But I can't change it,the method getElementById()
is return the type HTMLElement
;
var controlCheckbox= document.getElementById("mainCheckbox"),
addBtn = document.getElementById("btn_add"),
container = document.getElementById("observers");
ObserverSubject.extend(new ObserverSubject.Subject(), controlCheckbox);
controlCheckbox.onclick=()=>{
this.Notify(controlCheckbox.checked);
}
Try this simple cast:
var controlCheckbox = <HTMLInputElement>document.getElementById("mainCheckbox")
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