Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

0

Pure js way

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

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

over 4 years ago · Santiago Trujillo Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda