简体   繁体   中英

find row with a specific cell value

I have a function which finds a row within an html table whos first column contains a specific value...

$('#table tr').find('td:eq(0):contains(' + value + ')').parent();

The problem I have is that it returns all rows that have the number 1 in column 0 rather than just the row with 1. (ie, 1, 15, 21 etc..)

Is there an equivalent 'equals' to the 'contains' part of this search or some other way of doing this? I can't seem to find one.

The simplest would be to use filter :

$('#table tr').filter(function(){
   return $.trim($('td', this).eq(0).text())=="1";
});

Demonstration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM