Javascript DOM HTML Anchor hreflang Property get

Introduction

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.

Get the language code of a link:

var x = document.getElementById("myAnchor").hreflang;

Click the button to display the value of the hreflang attribute of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

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

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

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

<script>
function myFunction() {/* ww w  .j a va2  s  . co  m*/
  var x = document.getElementById("myAnchor").hreflang;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related