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