Assigning selectors to variables in jQuery

If we do…

var selector = $('.class');

We are actually storing the object.

Therefore doing…

$(selector).hide();

…later is pointless, we can just do…

selector.hide();

A colleague said he likes to prefix these object varibles with a $ symbol

var $selector = $('.class');
$selector.hide();
Posted Friday, November 16th, 2012 under Scrapbook.

Leave a Reply

*