Get value of the href element

<link rel="icon" type="image/png" href="[http://somesite.com">

I am trying to get the value of the href element but i get the error: TypeError: document.getElementsByTagName(…).getAttribute is not a function

var a =document.getElementsByTagName("link").getAttribute("href");
console.log(a)

Change it to:

var a =document.getElementsByTagName("link")[0].getAttribute("href");

getElementsByTagName() creates an array of such elements (even though you only have one). It is not like getElementById where there is only one possible element with that attribute. You have to specify which one.