How to get local href value from anchor (a) tag with JavaScript?

Spread the love

Sometimes, we want to get local href value from anchor (a) tag with JavaScript.

In this article, we’ll look at how to get local href value from anchor (a) tag with JavaScript.

How to get local href value from anchor (a) tag with JavaScript?

To get local href value from anchor (a) tag with JavaScript, we get the href property.

For instance, we write

const url = document.getElementById("aaa").href;

to select the link with getElementById.

Then we get the href attribute’s value with the href property.

Conclusion

To get local href value from anchor (a) tag with JavaScript, we get the href property.

Leave a Reply

Your email address will not be published.