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

191
Visualizações
How to replace text of each DOM node using jQuery?

I would like to know how I could parse the DOM using jQuery and modify the text of each node in order to translate a page of my site. Using jQuery is a constraint, not a choice :)

To be more precise, I would like to go through the DOM, to target each node which contains text, to translate it using an API and to replace the original text with the translated one.

I feel a little bit lost even if it seems pretty simple. Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If I get you correctly, you will have something like

// use $('*') instead if you really want to use jQuery
Array.from(document.querySelectorAll('*')).forEach(async _ => {
  _.textContent = await myTranslationApi(_.textContent);
});

However, I will have to say that it a) is slow to render the page with the wrong language and then replace it (this could also lead to flash of untranslated text) and b) might be error-prone to simply feed the textContent into your translation API (you probably want to search for translation keys and only replace them).

about 4 years ago · Juan Pablo Isaza 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