Skip to content Skip to sidebar Skip to footer

Filter Html Table By Color

I have a PHP script that is rendering an HTML table. I'm using Javascript to filter and sort the table from there using this. The issue I have is that I need to filter by color of

Solution 1:

If you set bgcolor as your attribute you could do:

$('table tr[bgcolor!="#FF0000"]').hide();

Or, as Teemu said, bgcolor is deprecated and you set it via CSS you could do:

$('table tr').filter(function() {
    return $(this).css('backgroundColor') != 'rgb(255, 0, 0)';
}).hide();

Fiddle

Solution 2:

You should be able to construct a jQuery filter for selecting those elements. Another approach is to use a specific class (w/ the color) for each and then filter rows by class.

Solution 3:

Something like this, using jQuery :

$('table td').each(function(){
   if($(this).attr('bgcolor') != '#FF0000'){
      $(this).hide(); // or .css('display', 'none'); or whatever to hide it.
   }
});

Post a Comment for "Filter Html Table By Color"