var language = document.documentElement.getAttribute('lang');
The example above retrieves the value of the
lang attribute of the
documentElement, and saves it to the variable language.
On an HTML page the
documentElement is the root
html element, so if it looked like this
Then the language variable would have the value
The name of the attribute to retrieve.
Get the value of an attribute with the specified name.
This method is for working with non-namespaced attributes; to get a namespaced attribute, use the DOM 2
getAttributeNS method instead.
The attribute value; if the attribute is not defined this method should return an empty string, however most browsers return
This is badly broken
This method is badly broken in all browsers, particularly Internet Explorer, so you should avoid using it wherever practical.
srcor event-handlers), favour that mapping instead, or consider using