0

I discovered that I can do this to grab rows of a dynamic table between 2 and 5:

var limitTable = $(table).find('tr:gt(2):lt(5)');

But I can't do this:

var temp1 = 2;
var temp2 = 5;

var limitTable = $(table).find('tr:gt(temp1):lt(temp2)');

In my situation, I can't hard code values in the "gt( )" and "lt( )". It will depend on an incremented variable. Not sure what to do. JSFIDDLE

1
  • need to use string concatenation to create the final selector using your variables Commented Dec 17, 2014 at 19:15

1 Answer 1

1

You have a mistake on your strategy to use temp1 and temp2. Use this to build the condition dynamically (notice how I concatenate variables)

var limitTable = $(table).find('tr:gt(' + temp1 + '):lt(' + temp2 + ')');
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. I understand string concatenation but if I have temp1 = 2, what's +temp1+? Not sure I understand.
@Matthew Moon: the concatenation will add the value of temp1 (in your case 2). The result will be 'tr:gt(2) for temp1=2
I see. It's the first time I've seen the +var+ notation. Thanks.

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.