How to get the value of the href attribute of <a> HTML tag in JavaScript

1 Answer

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

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


<script>        

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

/*
run:
  
http://www.collectivesolver.com/
    
*/

</script>

<button onclick="gethrefAttribute()">Get href attribute</button>

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

</body>
</html>

 



answered Aug 11, 2015 by avibootz

Related questions

...