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?
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?
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');
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.