Get href of anchor from mouse event

Hi! Just curious is it possible to get anchor href value from mouse event? I have code like this:

<a class="xtrasmall center" herf="/signup" (click)="open($event)">Create</a>

and in code I’m trying to get the link using

public open(e: MouseEvent): void {
  console.log((e.target as HTMLAnchorElement).href, (e.currentTarget as HTMLAnchorElement).href);
  xd.shell.openExternal(e.target.href);
}

but it’s always undefined. Am I doing something wrong here?

It may be that we’re not exposing the href attribute to JS… try using getAttribute("href") and see if that behaves any better.

Running following script:

console.log(anchor.tagName, anchor.getAttribute("href"), anchor.getAttribute("HREF"));

I got A undefined undefined.
I can’t execute getAttributeNames as there is no such function :frowning:
Per documentation HTMLAnchorElement must have href: https://adobexdplatform.com/plugin-docs/reference/uxp/class/HTMLAnchorElement.html#htmlanchorelement-href

I looked at our source code, and we’re exposing href as a getter and a setter to JS, so I’m surprised this isn’t working.

Out of curiousity, can you access pathname or protocol either? If you log anchor instanceof HTMLAnchorElement, does that log true?

Ha, I found it, it’s my mistake. In initial layout it’s herf instead of href. My bad, sorry about that :frowning:

That’s OK – no worries! Glad you got it figured out :slight_smile: