Reputation: 1221
I've 3 nested tables with innermost table containing some text in the td portion.
What is the way to get the innermost table containing this text?
If I run something like:
$("td").filter(function(){ return $(this).text().match(/PNR No:/);}).closest('table')
it gives me 3 tables
Upvotes: 2
Views: 68
Reputation: 241048
It gives me 3 tables
It's returning 3 tables because each td
element presumably contains that text (since they are nested).
What is the way to get the innermost table containing this text?
If you want to select the innermost td
element, one solution would be to select the td
elements that don't contain table elements (i.e., the innermost td
elements) by combining the :not()
pseudo class and the :has()
selector:
$("td:not(:has(table))").filter(function() {
return $(this).text().match(/PNR No:/);
}).closest('table');
Upvotes: 1