Joelio
Joelio

Reputation: 4691

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

Upvotes: 4

Views: 11707

Answers (2)

Mihai P.
Mihai P.

Reputation: 9357

$('#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.

Upvotes: 6

Selvakumar Arumugam
Selvakumar Arumugam

Reputation: 79830

Try using a filter. See below,

$j('#trends_table td').filter(function () {
  return $.trim($(this).text()) == 'Page Fans';
});

Upvotes: 9

Related Questions