Create a Base Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Base


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

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

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

function myFunction() {
    var x = document.createElement("BASE");
    x.setAttribute("href", "");

    document.getElementById("demo").innerHTML = "created a BASE element in the HEAD section";


Related Tutorials