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

331
Views
Thymeleaf and Javascript. Retrieving the value to javascript, but displaying text in the HTML

Very much a newbie here, so bear with me!

I'm trying to display a description from an object, but want javascript to retrieve another value (which can be from "1 to 100") from the object and set the background colour according to it's value. If I set the text to be this value, all works fine, but I really want to hide this "1 to 100" and display the description in th:text instead while still getting the javascript to retrieve the "1 to 100" do its thing.

Here's a snippet of the html

<div th:each="item : ${myObject.getItems()}">
    <td style="font-size: 10px;" class="valueTD" th:text="${item.getDescription()}" th:value="${item.getValue()}"></td>
</div>

Here's the javascript

var colorTDs = $('.valueTD');
$.each(colorTDs, function (index, colorTD) {
    var value = $(colorTD).html();
    if (!isNaN(value)) {
        var color = GreenYellowRed(value);
        $(colorTD).css('background-color', "rgb(" + color+ ")");
    }
});

As I say, if I set the th:text to be ${item.getValue()} it's all good.

I suspect it's something around the var colorTDs = $('.valueTD') but can't for the life of me work it out.

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