Link hreflangProperty
Link Object
Definition and Usage
The hreflang attribute specifies the language of the text in the linked document.
Syntax
Set the hreflang attribute:
linkObject.hreflang="language-code"
Return the hreflang attribute:
linkObject.hreflang
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the hreflang attribute
Example
Example
Display the language of the linked document:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<link id="link1" href="domoarigato.htm.html" hreflang="ja">
<script>
function displayResult(){
var x=document.getElementById("link1").hreflang;
alert(x);
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">Display the language of the linked document</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example (example.com)</title>
<link id="link1" href="domoarigato.htm.html" hreflang="ja">
<script>
function displayResult(){
var x=document.getElementById("link1").hreflang;
alert(x);
}
</script>
</head>
<body>
<button type="button" onclick="displayResult()">Display the language of the linked document</button>
</body>
</html>
Try it »
Link Object Other Extensions