I am setting background colors to all cells in a table. Within the table there is only numeric data. The code below works. It sets the background of numbers bigger then 10 to green and lower or equal to 10 to red.
.css({'background-color': value > 10 ? 'green' : 'red'})
But when to want set three different colors as background I do not know how to put it in JavaScript properly. I want a ternary expression within a ternary expression. The code below should be close to the solution. I want to set the background of numbers bigger then 10 to green and lower then 5 to red. The numbers between 5 and 10 should be getting an orange background.
.css({'background-color': value > 10 ? 'green' : 'background-color' : value < 5 ? 'red' : 'orange'})
What is wrong with the code?
{'background-color':…}in the inner ternary expression? Don’t do that.ternaryoperator. Unlikeif-elsestatements the ternary operator is an expression, which can be used inside function argument lists or object/array literals.