Home  >  Article  >  Web Front-end  >  How to search the value of a link's href attribute in JavaScript?

How to search the value of a link's href attribute in JavaScript?

王林
王林forward
2023-08-31 11:01:02909browse

How to search the value of a links href attribute in JavaScript?

#To get the href attribute value of a link in JavaScript, use the href attribute. It can give the URL of the linked document in JavaScript.

Example

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

Online Demo

<!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>

The above is the detailed content of How to search the value of a link's href attribute in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete