Check if event target is hyperlink
You should get it through
if(event.target.tagName.toLowerCase() === 'a')
{
event.target.href; //this is the url where the anchor tag points to.
}
You could check the tagName
property, as said by @parthik-gosar.
Another way is to use the instanceof
operator to check the element class (hyperlinks are of type HTMLAnchorElement
):
if (event.target instanceof HTMLAnchorElement) {
console.log(event.target.href);
}