Change Between 3 Different Background Color Based On Cell Value But Only If Another Call Value Is Different Than
I was helped along a while back with some code for changing background color in a table cell; the final solution works very well: change between 3 different background color based
Solution 1:
Here it is my friend: jsFiddle
It gets the value of avai :
var diff = $('td.avai').html();
then checks if the value of the avai
cell is other than 20, and skips the cell colouring:
if(diff != 20) { ... }
Solution 2:
if i understand right this is what you want?
// JavaScript Documentvar cell = $('td.bg_status');
// Get the td valuevar avai_value = $('.avai').text();
cell.each(function() {
var cell_value = $(this).html();
// continue if td value is not 20if(avai_value!=20){
if ((cell_value >= 0) && (cell_value <=19)) {
$(this).css({'background' : '#FF9900'});
} elseif ((cell_value >= 20) && (cell_value <=39)) {
$(this).css({'background' : '#99cc00'});
} elseif (cell_value >= 40) {
$(this).css({'background' : '#99ccff'});
}
}
});
Solution 3:
I forgot to mention earlier that my site is running Joomla! 3. I was just informed that Joomla doesn't allow to use $ signs for a while for jQuery codes. Also the line with avai_value caused an error and had to be rewritten like so:
// JavaScript Documentif(jQuery('td.avai').length){
var cell = jQuery('td.bg_status');
var diff = jQuery('td.avai').html();
cell.each(function() {
var cell_value = jQuery(this).html();
if(diff != 20) {
if ((cell_value >= 0) && (cell_value <=19)) {
jQuery(this).css({'background' : '#FF9900'});
} elseif ((cell_value >= 20) && (cell_value <=39)) {
jQuery(this).css({'background' : '#99cc00'});
} elseif (cell_value >= 40) {
jQuery(this).css({'background' : '#99ccff'});
}
}
});
}
Post a Comment for "Change Between 3 Different Background Color Based On Cell Value But Only If Another Call Value Is Different Than"