Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
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 = ????

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report

0

Pure js way

var lang = document.getElementsByTagName("html")[0].getAttribute("lang");

http://jsfiddle.net/loktar/ZRvE6/

over 4 years ago · Santiago Trujillo Report

0

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

document.documentElement.lang;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!