0

How to Set a background color for data table matched content like progress, Delete, Active, Pending,... There is no class and id for the matched content.

Example:

<span class="" >progress</span>--> bg color:green
<span class="" >Delete</span>--> bg color:red
<span class="" >Active</span>--> bg color:orange
<span class="" >pending</span>--> bg color:blue`
LW001
  • 2,452
  • 6
  • 27
  • 36
VinodReddy
  • 23
  • 9
  • Something like is mentioned here: https://stackoverflow.com/questions/9656774/how-do-i-conditionally-color-the-background-in-a-table-cell ? – Kukeltje Oct 03 '17 at 18:20
  • 1
    Hmmm I only now see you state there is no class or id... And you cannot add that? Seriously not? Weird... Then this question is 9999% certain not jsf related... not angularjs, not arrays, not jquery and not spring-boot-starter but plain html/css/javascript... Bad tagging then – Kukeltje Oct 03 '17 at 18:25

1 Answers1

0

You have not given enough data for this question but i'll try to help then you may have an idea to improve it according to your needs.

<span class="asd" >progress</span>
<span class="asd" >delete</span>
<span class="asd" >active</span>
<span class="asd" >pending</span>

var y = $('.asd').length;
for(x=0; x<y; x++){
  if($('.asd').eq(x).text() == "progress"){
    $('.asd').eq(x).css('background-color','green');
  }
}

You can add more if else or switch function to check which one match with and define color. Switch better i belive in this situation.

Güney Saramalı
  • 791
  • 1
  • 10
  • 19
  • Bad suggestion imo... If OP can set a value of the span, he/she can also add a custom class to it... No need for javascript like this... https://stackoverflow.com/questions/9656774/how-do-i-conditionally-color-the-background-in-a-table-cell?rq=1 – Kukeltje Oct 03 '17 at 18:19
  • As I told at the begining, i said there is not enough data. Then i had to suppose that he can. class is not the only way to grab elements but again as there is NOT enough data that was the simplies way. If he could give us the parent element then we could target it and use find('span') to grab them again. Are we together? – Güney Saramalı Oct 03 '17 at 18:22
  • Sorry, I only now read OP does not have a class... Strange... as there IS a value... I still have the impression OP has no access to some sort of code and needs to fix it in this way... – Kukeltje Oct 03 '17 at 18:22
  • Yes, if he needs a decent working answer then he should provide more data which is let us to find a way to target spans ;) – Güney Saramalı Oct 03 '17 at 18:24