Is referencing a selector faster in jquery than actually calling the selector? if so, how much does it make a difference?

Posted by anthonypliu on Stack Overflow See other posts from Stack Overflow or by anthonypliu
Published on 2011-01-11T05:37:42Z Indexed on 2011/01/11 6:53 UTC
Read the original article Hit count: 186

Filed under:
|

Hi, I have this code:

$(preview-button).click(...)
$(preview-button).slide(...)
$(preview-button).whatever(...)

Is it a better practice to do this:

var preview-button = $(preview-button);
preview-button.click(...);
preview-button.click(...);
preview-button).slide(...);
preview-button.whatever(...);

It probably would be better practice to do this for the sake of keeping code clean and modular, BUT does it make a difference performance wise? Does one take longer to process than the other? Thanks guys.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-plugins