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

335
Vistas
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 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