Reputation: 23
I have a 'search' function for my HTML table which is populated from a database. I have the following code which is activated through a button and a text box with the ID entered.
I am trying to get the next/second TD in that rows text/value. I can successfully get the first TD but not the second. Any ideas?
function search() {
var valueToFind = $('#EnterSiteNo').val();
$('#SiteTable > tbody> tr').each(function(index) {
var firstTd = $(this).find('td:first');
var secondTd = $(this).find('td:second');
if ($(firstTd).text() == valueToFind) {
var name = secondTd.text();
alert("found. " + name);
}
})
}
Upvotes: 1
Views: 116
Reputation: 3453
Please try using td:nth-child(2)
as the selector.
jQuery Select first and second td
Upvotes: 0
Reputation: 2621
you should try td:nth-child()
instead of :second
So here you should change your code to
var secondTd = $(this).find('td:nth-child(2)');
Upvotes: 1