The lang property sets or gets the value of the lang attribute of an element.
Ge the language code of a <p> element:
var x = document.getElementById("myP").lang;
<!DOCTYPE html> <html> <body> <p id="myP" lang="en">Click the button to display the language code of this p element.</p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . j a v a 2 s .co m var x = document.getElementById("myP").lang; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
The lang attribute sets the language code of the element's content.
Common examples are "en" for English, "es" for Spanish, "fr" for France and so on.
Property Values
Value | Description |
---|---|
language_code | Specifies the language code for the element's content. |
The lang property returns a String representing the language of the element's text.