Javascript DOM HTML Base Object get

Introduction

The Base object represents an HTML <base> element.

We can access a <base> element by using document.getElementById():

Click the button to get the URL of the base element.

View in separate window

<!DOCTYPE html>
<html>
<head>
  <base id="myBase" href="https://www.java2s.com/">
</head>/*from  ww w .  j  a  v  a  2  s .c o  m*/
<body>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myBase").href;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related