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

287
Visualizações
How to get HTML's thymeleaf value in javascript?

enter image description here

I send values using model.addAttribute in Spring, so I get values in HTML file well. and I want to get values in js files so I use document.getElementById but I can't get the value but 0 .. How to get html thymeleaf value in js? Thank you all..

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

0

This you find this documented here: https://www.concretepage.com/thymeleaf/thymeleaf-javascript-inline-example-with-variable

The part which is interesting to you is the following:

<script th:inline="javascript">

/*<![CDATA[*/
  var user = /*[[${session.userName}]]*/ 'User Name';

/*]]>*/
</script>

In your case of course instead of session.userName you would put your variable name.

<script th:inline="javascript">

/*<![CDATA[*/
  var user = /*[[${modelVariable}]]*/ 'User Name';

/*]]>*/
</script>
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