How to obtain lang attribute in HTML using JavaScript?

JavascriptHtml

Javascript Problem Overview


How to obtain lang attribute in HTML using JavaScript?

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

Javascript Solutions


Solution 1 - Javascript

If both attributes agree on their values (as they should), it's enough to read either of them. I'd suggest using

document.documentElement.lang

Solution 2 - Javascript

Just.

document.getElementsByTagName('html')[0].getAttribute('lang');

And with the namespace

document.getElementsByTagName('html')[0].getAttribute('xml:lang');

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGordian YuanView Question on Stackoverflow
Solution 1 - JavascriptChristophView Answer on Stackoverflow
Solution 2 - JavascriptChristophe EbléView Answer on Stackoverflow