Visit Mozilla.org

DOM:element.lang

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

This property gets or sets the base language of an element's attribute values and text content.

[edit] Syntax and values

var languageUsed = elementNodeReference.lang;
elementNodeReference.lang = NewLanguage;

languageUsed is a string variable that gets the language in which the text of the current element is written. NewLanguage is a string variable with its value setting the language in which the text of the current element is written.

[edit] Example

// this snippet compares the base language and 
// redirects to another url based on language
if (document.documentElement.lang == "en") 
   {
    window.location.href = "Some_document.html.en";
   }
else if(document.documentElement.lang == "ru")
   {
    window.location.href = "Some_document.html.ru";
   };

[edit] Notes

The language code returned by this property is defined in RFC 1766. Common examples include "en" for English, "ja" for Japanese, "es" for Spanish and so on. The default value of this attribute is unknown. Note that this attribute, though valid at the individual element level described here, is most often specified for the root element of the document.

[edit] Specification

W3C DOM Level 2 HTML: lang