user1869407 user1869407 - 2 months ago 18
HTML Question

Find specific table row containing substring text of a jquery variable of html

I have a jquery object called

$(stuff)
.

Inside
$(stuff)
is a bunch of html code containing a variable number of
<table>
s and I want to take a look at just that first table in the html.

Inside this first table I want to search the first column(or really any column) to find a substring with a value of "9.5"

I want to know how many rows down "9.5" is in that table and return that value.

Idea of code to perform the operation(does NOT work):

var tableRow = $(stuff).filter(function () {
return $('td' + ":contains(9.5)");
}).closest("tr");

Answer

There is no need to make it more complex simply do as follows.

var tableRow = $(stuff).find("tr:contains(9.5)");


More specific one using :has() pseudo-class selector.

var tableRow = $(stuff).find("tr:has(td:contains(9.5))");