Anchor hreflang Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

The hreflang property sets or gets the value of the hreflang attribute of a link.

The hreflang attribute sets the language of a linked document.

Property Values

ValueDescription
languagecode Sets a two-letter language code for the language of the linked document.

Return Value

A String, representing the language of the linked document

The following code shows how to Get the language code of a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" hreflang="en-us" href="https://www.java2s.com/">java2s.com</a></p>

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

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

<script>
function myFunction() {/*from w  ww .j a  v  a2s. c o  m*/
    var x = document.getElementById("myAnchor").hreflang;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials