Search Href Attribute Value of a Link in JavaScript



To get the value of the href attribute of a link in JavaScript, use the href property. It gives you the URL of the linked document in JavaScript.

Example

You can try to run the following code to get the value of the href attribute of a link.

<!DOCTYPE html>
<html>
   <body>
      <p><a id="anchorid" href="https://www.qries.com/">Qries</a></p>
      <script>
         var myLink = document.getElementById("anchorid").href;
         document.write("Link: "+myLink);
      </script>
   </body>
</html>
Updated on: 2023-11-18T03:22:23+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements