Categories
JavaScript Answers

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 can use the href property.

For instance, we write

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

to get the anchor element with ID 'aaa' with getElementById.

And then we get the href attribute value with href.

Conclusion

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

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *