Create a Base Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Base

Introduction

You can create a <base> 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  .co  m*/
<body>

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

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

<script>
function myFunction() {
    var x = document.createElement("BASE");
    x.setAttribute("href", "https://www.java2s.com");
    document.head.appendChild(x);

    document.getElementById("demo").innerHTML = "created a BASE element in the HEAD section";
}
</script>

</body>
</html>

Related Tutorials