Create a Link Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Link

Introduction

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

Demo Code

ResultView the demo in separate window

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

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

<script>
function myFunction() {
    var x = document.createElement("LINK");
    x.setAttribute("rel", "stylesheet");
    x.setAttribute("type", "text/css");
    x.setAttribute("href", "http://java2s.com/style/bootstrap.min.css");
    document.head.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials