In this section, we will learn what the Element lang property is and how to use it in JavaScript.
What is Element lang Property in JavaScript?
The JavaScript Element lang property is used to get or set the value of the lang attribute for an HTML element.
Note: please check the HTML lang attribute section if you’re not familiar with this attribute. In short, this attribute is used to set the language code of the content in an HTML element.
JavaScript lang Property Syntax:
element.lang; element.lang = language_code;
JavaScript lang Property Input Value
The value we set for the lang property is a language-code.
JavaScript lang Property Return Value
The return value of this property is the current language-code that is set for the attribute in a string form.
Note: an empty string will return if this attribute is not set for the target element.
Example: HTML lang attribute with lang Property in JavaScript
See the Pen HTML lang attribute with lang Property in JavaScript by Omid Dehghan (@odchan1) on CodePen.