According to the spec, language is inherited from the nearest ancestor element which has lang
set. So how do I get the language of one of these descendents?
I'm setting the language with the lang
attribute:
<div id="outer" lang="es">
<div id="inner">¿Por qué?</div>
</div>
And trying to access it with the lang
property:
alert(document.getElementById('outer').lang);
alert(document.getElementById('inner').lang);
I pretty quickly noticed that the lang
property of the inner div isn't the inherited language (or it's not inheriting; no idea). This fiddle demonstrates the behavior I'm seeing.
How can I determine an element's language with Javascript? I'm really looking to take advantage of the inheritance of the lang
attribute, as I also need this to work with screen-readers.