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

235
Visualizações
Insert Thymeleaf HTML with JavaScript jquery

I am trying to insert HTML code with JavaScript, but the Browser does not show Thymeleaf rendered

$('<span [[$ th:text#{some.property.key}]]  id="counter" class="UI-modern"> 
   </span>').insertAfter("#article");

HTML code

<p id="article">Example text</p>

The key some.property.key is the property. In Thymeleaf it would look like this:

<span th:text="#{some.property.key}" id="counter" class="UI-modern">
</span>

I would like to write the above code with JavaScript jquery insertAfter() below the id "article"

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

0

Thymeleaf does not work on .js files It is not clear why you can't just rebder this element using Thymeleaf like the example you gave. You can give that span an ID and then reference it with JS

about 4 years ago · Juan Pablo Isaza Relatório

0

Intead of trying to use Thymeleaf HTML attributes in JavaScript, you can use JavaScript inlining and build your HTML that way. For example:

<script th:inline="javascript">
  let text = /*[[#{some.property.key}]]*/ "";
  $('<span id="counter" class="UI-modern"></span>').text(text).insertAfter("#article");
</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