html - Add a css class on td of table according to TD less or more value -


i have table in html 2 td content in it. dynamic td. want implement functionality if in each of table row, each big td value text color displayed green , less value text display red;

please find source code:

fordata+='<tr><td>'+forplant+'</td><td>'+forasking+'</td><td>'+forproduction+'</td></tr>';                 $(".fortable").append(fordata);                 if(forasking<forproduction){                     console.info("less value"); //-----here want display whatever value less displayed red , other green                 }else{   //---same manner followed in there                     console.info("more asking");                 } 

create 2 classes colors

.green{ color:green; }  .red{ color:red; } 

then first compare values append result.

fordata+='<tr><td>'+forplant+'</td>';  if(forasking<forproduction){                     fordata+='<td class="green">'+forproduction+'</td><td class="red">'+forasking+'</td>';                  }else{                      fordata+='<td class="green">'+forasking+'</td><td class="red">'+forproduction+'</td>';                 }  fordata+= '</tr>';   $(".fortable").append(fordata); 

you can see demo here


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -