Reputation: 9681
var $container = $('div#myContainer');
var $panels = $('div#myContainer > div');
Is it possible to reuse the selector I've already cached in $container within the next child selector?
Upvotes: 2
Views: 500
Reputation: 630489
You can do:
var $container = $('div#myContainer');
var $panels = $container.children('div');
This selects only the children like you have currently, using it as the context argument actually calls .find()
internally, finding all descendants instead of only direct children.
Upvotes: 3
Reputation: 75650
Yes!
var $container = $('div#myContainer');
var $panels = $('div', $container);
This makes use of the additional context
argument with the standard jQuery() function. You can read up on it here: http://api.jquery.com/jQuery/#jQuery1
You could also do this.
var $container = $('div#myContainer');
var $panels = $container.find('div');
Upvotes: 1