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