Base href Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Base


The href property sets or gets the href attribute in a base element, which controls a base URL for all relative URLs on a page.

Set the href property with the following Values

Value Description
URL Sets the base URL

Return Value

A String, representing the base URL for all relative URLS on a page

The following code shows how to return the base URL for all relative URLs on a page:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<base id="myBase" href="/jsref/">
</head>/*from   w w  w  .j  a v a  2 s  .  co  m*/

<a href="default.asp">Default</a>

<button onclick="myFunction()">Test</button>

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

function myFunction() {
    var v = document.getElementById("myBase").href;
    document.getElementById("demo").innerHTML = v;


Related Tutorials