Create a Link Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Link


You can create a <link> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
</head>//from w w w . j  a v a  2  s.c o m

<button onclick="myFunction()">create a LINK element</button>

function myFunction() {
    var x = document.createElement("LINK");
    x.setAttribute("rel", "stylesheet");
    x.setAttribute("type", "text/css");
    x.setAttribute("href", "");


Related Tutorials