Return the language code of the linked document:
var x = document.getElementById("myLink").hreflang;
Click the button to return the language code of the linked document.
The hreflang
attribute does not render as anything special in any of the major browsers.
It can be used by search engines.
<!DOCTYPE html> <html> <head> <link id="myLink" href="https//java2s.com" hreflang="ja"> </head>//from w w w. j av a 2s .com <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myLink").hreflang; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The hreflang
property sets or gets the language code of the linked document.
The hreflang
attribute does not render in any of the major browsers.
The hreflang
property accepts and returns a String value.
Value | Description |
---|---|
languagecode | Specifies the language code of the linked document |
The hreflang
property returns a String representing the language code of the linked document.