Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery find table cell with value

I have a table with id trends_table. I want the cell with the exact match of "Page Fans"

 $j("#trends_table td:contains('Page Fans')")

This gives me all cells that contain, how do I do equals? I have fiddled with a bunch of syntax but nothing I can find works.

I see this, Jquery find table cell where value is X but dont see how I would do it for a given table, dont understand the context.

thanks Joel

like image 787
Joelio Avatar asked Dec 06 '22 10:12

Joelio


2 Answers

Try using a filter. See below,

$j('#trends_table td').filter(function () {
  return $.trim($(this).text()) == 'Page Fans';
});
like image 68
Selvakumar Arumugam Avatar answered Dec 11 '22 09:12

Selvakumar Arumugam


$('#trends_table td').filter(function() {
    return $(this).text() == 'Page Fans';
}).css('background-color', 'red');

Here is an example of what you try to accomplish. http://jsfiddle.net/bQdpp/1/ .In this example I just turn the cells red, take care if more then 1 cell is returned then all the cells are turned red.

like image 32
Mihai P. Avatar answered Dec 11 '22 10:12

Mihai P.