Search code examples
javascriptjquerycssflexigrid

Setting colours to FlexiGrid rows depending on column value or attribute href column value


Having a flexigrid table, I want to remove an icon that contains inside its href a "remove" string, but also I want to change the color of that row

To color in red I could use column 2, if it is empty it would be in red, Or if 3rd column if it has "remove" string the row should be red...

 <a href="remove" class=" crud-action" title="ADD R">

to do that I am using

$(function () { $('a[href="remove"]').remove(); } ); //to remove icon

$("tr").each(function() {
    var st = $(this).find("td").eq(1).text();
    if (st == ''){
    $(this).css("color", "red");
    }
    else{
    $(this).css("color", "green");

    }
});

However when looping on rows it is only changing the header row to red, I am getting this result insetad of crows 2 and 5 in red

enter image description here

How to color respective 2 and 5 rows in red and other in green ?

Here is a jsfiddle


Solution

  • If you really dont want "&nbsp" (A space) in div within td, Just try this code.

    $('tr:has(td > div:empty)').css("color","red");
    

    Fiddle