Typescript: How to check tagName in eventTarget?

I would adjust that code snippet like this:

var ele = <HTMLDivElement>document.getElementById("toolbar");
    ele.addEventListener("click", (ev: MouseEvent) => {
        var element = ev.target as HTMLElement;     
        if (element.tagName === "SPAN") { 
            console.log(element.tagName) 
        }  
    }, false);

Casting the event property target to HTMLElement will give us all the proper properties of the underlying element.

Check it in the playground

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)