Javascript DOM HTML Base Object create

Introduction

The Base object represents an HTML <base> element.

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

var x = document.createElement("BASE");

Click the button to create a BASE element.

View in separate window

<!DOCTYPE html>
<html>
<head>
</head>//from  w w  w .ja va  2 s  . c o  m
<body>
<button onclick="myFunction()">Test</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 = "BASE element created.";
}
</script>

</body>
</html>



PreviousNext

Related