0
var $slideObj = $('#slideshow .slideItem'); var num = 10; 

I got that code and I want to find the nth-child of the "$slideObj" element. The code below works but I want to use the variable instead of finding the element again.

var $currentSlideObj = $('#slideshow .slideItem:nth-child(' + num + ')'); 

What I want is the following, $slideObj.nth-child(num); I have tried the following below.

$slideObj.find(':nth-child('+num+')'); $slideObj.eq(num); 

1 Answer 1

2

You actually already have all the "children" in your $slideObj.

You need to use .filter rather than .find (filter the current result set, not look deeper in the tree).

$slideObj.filter(':nth-child(' + num + ')'); 
Sign up to request clarification or add additional context in comments.

1 Comment

Worked! Keep forgetting about the filter method.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.