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")