1
Guys someone could help me with this js please?
I need the label to change according to the text, if it is "victory" is Success and is "defeat" is Danger, follow code below:
notes my ${resultad.statusResults} brings from the bank only "Win" and "Lose" and it prints this information on the screen, IE, really my js must 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>
Mark really your code is correct, I tested your example on the link, but when I put inside mine . jsp it does not run something must be conflicting that it does not work.
– user98426
press F12 and go to console, and put what is appearing error here, then I can help better, go to the browser you are using
– Marcos Brinner
home:34 Uncaught Referenceerror: $ is not defined at home:34 (Anonymous) @ home:34 - ( and it points to this line of the script: ) - $(Document). ready(Function () {
– user98426
check whether the Jquery file is being called, and whether it appears before the script because this error says that Jquery is not defined at the time the function is running
– Marcos Brinner
If this doesn’t resolve try to check the jQuery.noConflict()
– Marcos Brinner
i pasted jquery inside the <head>
– user98426
yeah, it didn’t happen! I’ll keep trying here.
– user98426
eheh, good luck at most, but check if the path of Jquery is correct, or try to use pure javascript would also be an option
– Marcos Brinner
Dude, "In order for it to work properly, in your HTML you must import jQuery first and then your script" that nonsense né hahahahaha solved!!! Vlw Marcos, thanks for your help too.
– user98426
haha, good that you solved, kkkk because it is you have to reference before the library as I had said
– Marcos Brinner
if the reply helped you mark with
– Marcos Brinner
You spoke and I did not notice, you are correct! I wanted to give the solution in the text that you say it and not in the code above, as I do?
– user98426
Just edit your reply and put below it the solution
– Marcos Brinner