Get Link Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Link


The Link object represents an HTML <link> element.

You can access a <link> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<link id="myLink" rel="stylesheet" type="text/css" href="">
</head>/*from  w  ww.  j av  a  2s .c om*/

<h1>I am formatted with a linked style sheet</h1>

<button onclick="myFunction()">get the URL of the linked document</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("myLink").href;
    document.getElementById("demo").innerHTML = x;


Related Tutorials