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

HTMLJavascriptProgramming Scripts

To get the value of the target attribute of a link in JavaScript, use the target property. The target attribute is used to set where you want the linked document to open i.e. in the same window or new window or same frame, etc.

Example

You can try to run the following code to get the value of the target attribute of a link −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <p><a id="anchorid" rel="nofollow" target= "_blank" href="https://www.qries.com/">Qries</a></p>
      <script>
         var myVal = document.getElementById("anchorid").target;
         document.write("Value of target attribute: "+myVal);
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 14:27:52
Advertisements