Stefano Maglione
Stefano Maglione

Reputation: 4150

jQuery get li from variable containing ul

I need get li from a variable that contains ul which was previously received :

var previousPage= $( "ul" );
$(previousPage 'li') //Doesn't work

How can I do?

Upvotes: 0

Views: 407

Answers (1)

algorhythm
algorhythm

Reputation: 8728

Do it with the second parameter of $-method like this

var previousPage=$( "ul" );
$('li', previousPage);

This parameter specifies the context to search for the 'li'-tag...

And if you want the first li do this:

$('li', previousPage).first();

You can also combine the selectors like this:

$(previousPage.selector +' li');

Upvotes: 3

Related Questions