Computer >> Computer tutorials >  >> Programming >> HTML

HTML DOM Anchor hreflang Property


The HTML DOM Anchor hreflang property is used to set or return the value of the hreflang attribute of a link.

Following is the syntax to set the hreflang property −

anchorObj.hreflang = language_code

Above, language_code represents the language of the linked document. This language code examples, include en for English, bn for Bengali, hi for Hindi, fr for French, la for Latin, ru for Russian, etc.

Following is the syntax to return the hreflang property −

anchorObj.hreflang

Let us now see an example to implement the DOM Anchor hreflang property −

Example

<!DOCTYPE html>
<html>
<body>
<h1>Company</h1>
<p><a id="mylink" hreflang="en" href="https://www.abc.com:6064/abc/products.html">Products</a></p>
<h2 id="myid"></h2>
<button onclick="display()">Display href Part</button>
<button onclick="display2()">Display Host Part</button>
<button onclick="display3()">Display hreflang</button>
<script>
function display() {
   var a = document.getElementById("mylink").href;
      document.getElementById("myid").innerHTML = a;
   }
   function display2() {
      var a = document.getElementById("mylink").host;
      document.getElementById("myid").innerHTML = a;
   }
   function display3() {
      var a = document.getElementById("mylink").hreflang;
      document.getElementById("myid").innerHTML = a;
   }
</script>
</body>
</html>

Output

HTML DOM Anchor hreflang Property

Click the “Display hreflang” button −

HTML DOM Anchor hreflang Property