HTML | DOM lang Property
In HTML document, the lang property is used to set or return the value of the lang attribute of an element. This attribute specifies the language code of the element’s content. The element attribute takes “en” for English, “ja” for Japanese, “es” for Spanish and so on. The default value of this attribute is unknown.
Syntax:
Get the value of lang:
HTMLElementObject.lang;
Set new value for lang:
HTMLElementObject.lang = language_code;
The language_code specifies the language code for the element’s content. This property returns a string which represents the language of the element’s text.
Example-1: Assign the value of language code.
<!DOCTYPE html> <html> <head> <title> HTML | DOM lang Property </title> </head> <body> <p id="para1" lang="en"> Click the button to display the language code of paragraph. </p> <button onclick="myFunction()"> Display Language </button> <p id="para2"></p> <script> function myFunction() { var x = document.getElementById("para1").lang; document.getElementById("para2").innerHTML = x; } </script> </body> </html> |
Output:
Before clicking the button:

After clicking the Display Language button:

Explanation:
The above example gets the language code of the first paragraph and assigns that language to the second paragraph.
Example-2: Check the value of language code.
<!DOCTYPE html> <html> <head> <title> HTML | DOM lang Property </title> </head> <body> <p id="para1" lang="ja"> Click the button to display the language code of paragraph. </p> <button onclick="myFunction()"> Display Language </button> <p id="para2"></p> <script> function myFunction() { if (document.getElementById("para1").lang === "ja") { document.getElementById("para2").innerHTML = "Japanese"; } else { document.getElementById("demo").innerHTML = "Not in Japanese"; } } </script> </body> </html> |
Output:
Before clicking the button

After clicking the Display Language button
Supported Browsers:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- HTML | lang Attribute
- HTML | DOM specified Property
- HTML | DOM URL Property
- HTML | DOM value Property
- HTML | DOM id Property
- HTML | DOM dir Property
- HTML | DOM Bdo dir Property
- HTML | DOM li value Property
- HTML | DOM name Property
- HTML | DOM characterSet Property
- HTML | DOM innerHTML Property
- HTML | DOM isContentEditable Property
- HTML | DOM implementation Property
- HTML | DOM Progress max Property
- HTML | DOM nextElementSibling Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



