How to get the value of the id attribute a link in JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To get the value of the id attribute of a link in JavaScript, use the id property. You can try to run the following code to get the value of the id attribute of a link −

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <p><a id="anchorid" hreflang="en-us" href="https://www.qries.com/">Qries</a></p>
      <script>
         var myID = document.getElementById("anchorid").id;
         document.write("Value of id attribute of a link: "+myID);
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 13:38:46
Advertisements