Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda