HTML DOM Anchor hreflang Property
Last Updated :
02 Jan, 2024
The DOM Anchor hreflang Property in HTML DOM is used to set or return the value of the hreflang attribute of a URL or a link. The hreflang attribute is used to specify the language for a linked document.
Syntax:Â
- It returns the hreflang property.
anchorObject.hreflang
- It is used to set the hreflang property.
anchorObject.hreflang = languagecode
Property Values:Â
- languagecode: It specifies the two letter code which represents the language of the linked document.
Return Value: It returns a string value which represents the language for the linked Document.
Example 1: This example returns the hreflang Property.Â
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Anchor hreflang Property
</ title >
</ head >
< body style = "text-align: center;" >
< h1 >GeeksforGeeks</ h1 >
< h2 >DOM Anchor hreflang Property</ h2 >
< p >Welcome to
id = "GFG" rel = "nofollow"
hreflang = "en-us" target = "_self" >
GeeksforGeeks
</ a >
</ p >
< button onclick = "myGeeks()" >
Submit
</ button >
< p id = "sudo" ></ p >
< script >
function myGeeks() {
let x = document.getElementById("GFG").hreflang;
document.getElementById("sudo").innerHTML = x;
}
</ script >
</ body >
</ html >
|
Output:
Example 2: This example sets the hreflang Property.Â
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM Anchor hreflang Property
</ title >
</ head >
< body style = "text-align: center;" >
< h1 >GeeksforGeeks</ h1 >
< h2 >DOM Anchor hreflang Property</ h2 >
< p >Welcome to
id = "GFG" rel = "nofollow"
hreflang = "en-us" target = "_self" >
GeeksforGeeks
</ a >
</ p >
< button onclick = "myGeeks()" >
Submit
</ button >
< p id = "sudo" ></ p >
< script >
function myGeeks() {
let x = document.getElementById("GFG")
.hreflang = "fr";
document.getElementById("sudo").innerHTML
= "The value of the hreflang attribute" +
" was changed to " + x;
}
</ script >
</ body >
</ html >
|
Output:
Supported Browsers:
- Google Chrome
- Internet Explorer 10.0 +
- Firefox
- Opera
- Safari
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...