Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!