Can anyone help me with this js please?
I need the label to change according to the text, if it is "victory" it is success and for "defeat" it gets danger, it follows code below:
Note my $ {resultad.statusResults) brings the bank only "Victory" and "Defeat" and it prints this information on the screen, that is, really my js should be bad: /
-
Script
<script> $(document).ready(function () { $("span").each(function () { if ($(this).text() === "Vitória") { //limpa class anterior $(this).removeAttr('class'); //adiciona class desejada $(this).addClass('label label-success'); } else if ($(this).text() === "Derrota") { //limpa class anterior $(this).removeAttr('class'); //adiciona class desejada $(this).addClass('label label-danger'); } }); }); </script>
-
html
<table class="table"> <thead> <tr> </tr> </thead> <tbody> <c:forEach items="${listaResultados}" var="resultad"> <tr> <td>${resultad.jogadorTemp}</td> <td>${resultad.placar1}</td> <td>${resultad.placar2}</td> <td>${resultad.oponenteTemp}</td> <td>${resultad.momento}</td> <td><span class="label label-success">${resultad.statusResultados}</span></td> </tr> </c:forEach> </tbody> </table>