1

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");
2
  • You can use $(stuff).find( "table:first tr:contains(9.5)"); if you are more specific to find the text only in first table . Commented Aug 26, 2016 at 20:12
  • Can you provide some sample code of table ? Commented Aug 27, 2016 at 11:32

1 Answer 1

1

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))");
Sign up to request clarification or add additional context in comments.

2 Comments

I put alert(tableRow); as the next line to see what the returned number is. It returns "[Object object]" in the alertbox. What gives?
@user1869407 : which returns the jQuery object.... get the text using alert(tableRow.text())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.