Link href Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Link

Description

The href property sets or gets the URL of a linked document.

Set the href property with the following Values

Value Description
URL Sets the URL of the linked resource/document

Return Value

A String, representing the URL of the linked document.

The following code shows how to return the URL of the linked document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<link id="myLink" href="http://java2s.com" hreflang="ja">
</head>/*ww w.  j a va  2s.  c o  m*/
<body>

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

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

<script>
function myFunction() {
    document.getElementById("myLink").hreflang = "en-us";
    document.getElementById("demo").innerHTML = "The language code was changed from 'ja' to 'en-us'.";
}
</script>

</body>
</html>

Related Tutorials