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

332
Visualizações
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
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