Reusing the selector reference, your first case, is definitely faster. Here’s a test I made as proof:
http://jsperf.com/caching-jquery-selectors
The latter case, redefining your selectors, is reported as ~35% slower.
More Related Contents:
- What is the fastest method for selecting descendant elements in jQuery?
- jQuery select by class VS select by attribute
- jQuery hasClass() – check for more than one class
- Performance of jQuery selector with context
- Why should I use Google’s CDN for jQuery?
- jQuery selectors with variables
- jQuery Selector: Id Ends With?
- Select element by exact match of its content
- jquery data selector
- Sort divs in jQuery based on attribute ‘data-sort’?
- How can I change CSS display none or block property using jQuery?
- Set selected option of select box
- How to select last child element in jQuery?
- jQuery dot in ID selector? [duplicate]
- jQuery :contains() selector uppercase and lower case issue
- CSS selector case insensitive for attributes
- jQuery get all divs which do not have class attribute
- Why cache jQuery objects?
- Difference between :hidden and :not(:visible) in jQuery
- jQuery object: to cache or not to cache?
- How can I get the corresponding table header (th) from a table cell (td)?
- Select elements without any class [duplicate]
- jQuery attribute selector for multiple values
- jQuery: selector (classname with space)
- JQuery data selector not updating with .data
- :nth-of-type() in jQuery / Sizzle?
- Changing the child element’s CSS when the parent is hovered
- addID in jQuery?
- CSS selector to select an id with a slash in the id name?
- Using jQuery how do I select a range of rows?