Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Get the Value of an Attribute</title> </head> <body> <p><a href="https://www.google.com/" target="_blank" id="myLink">Google</a></p> <script> // Selecting the element by ID attribute let link = document.getElementById("myLink"); // Getting the attributes values let href = link.getAttribute("href"); document.write(href); // Prints: https://www.google.com/ document.write("<br>"); let target = link.getAttribute("target"); document.write(target); // Prints: _blank </script> </body> </html>