Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of the lang attribute with jQuery?

Tags:

html

jquery

Suppose I have an HTML document that looks like this:

<html lang="en">
...
</html>

My question is: how to get the value of the attribute lang with jQuery?
I've tried $("html").attr("lang") but it did not work... any suggestions?

like image 546
PapelPincel Avatar asked Jul 27 '09 10:07

PapelPincel


2 Answers

Access the attribute directly, ex :

$('html')[0].lang
like image 96
OneOfOne Avatar answered Sep 25 '22 23:09

OneOfOne


You don't need to use jQuery for this.

The easiest way to retrieve the lang attribute is to access the lang property on the read-only documentElement object:

document.documentElement.lang;
like image 36
Josh Crozier Avatar answered Sep 25 '22 23:09

Josh Crozier