Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript: reading lang attribute in html tag

In <html> tag I have attribute lang. How do I reach it using .js. I want to use contains of lang as a variable. So as I understand it should start with var lang = ????

like image 588
JackLeo Avatar asked Sep 07 '25 13:09

JackLeo


1 Answers

In jQuery:

    var theLanguage = $('html').attr('lang');
    alert(theLanguage);

If you wanna fiddle: http://jsfiddle.net/NX367/

If you want to do it in plain Javascript, this site will explain better than I:
http://www.javascriptkit.com/dhtmltutors/domattribute.shtml

like image 90
Barrie Reader Avatar answered Sep 09 '25 05:09

Barrie Reader