How to get the target attribute of <a> HTML tag with JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>
  
<head>
</head>
  
<body>

<a id="a-id" target="_blank" href="http://www.collectivesolver.com/">collectivesolver</a>


<script>        

function get_a_target() 
{
    document.getElementById("p-id").innerHTML = document.getElementById("a-id").target;
}

/*
run:
  
_blank
    
*/

</script>


<button onclick="get_a_target()">Get a target</button>

<p id="p-id"></p>

</body>
</html>

 



answered Aug 14, 2015 by avibootz

Related questions

1 answer 248 views
1 answer 217 views
1 answer 212 views
1 answer 258 views
2 answers 396 views
2 answers 235 views
...