I have div with id #wrapper
and all element are inside it.
I'm caching wrapper by doing
var $wrapper = $('#wrapper');
Now any time i want to make a selector or reference an element, i do
$wrapper.find('#whatever').click(....
By doing this i avoid wrapping with jQuery object again, so any selector i do in the future will be based on the cached $wrapper
. But on the other when i use find()
with the cached $wrapper, i know it will search all elements inside #wrapper
. My questions is whic is better better, use cached variable along with find then issue click event, or just simply do $('#whatever').click(..
whatever
can be either a class or id.