[jQuery] Re: does selectors $ cache?

2009-05-27 Thread Andy Matthews

No, it does not cache. Each time you make a page query, a new call is made.
For better performance, always cache commonly used selectors:

$myID = $('#myID'); // $ used for initial var to indicate a jQuery object
var text = $myID.text();
var color = $myID.css('color');

Also, you should always use the raw ID reference where possible as it's far
more performant than tacking on a tag name first:

$myID = $('#myID'); // this performs better than the line below
$myID = $('div#myID'); // avoid this where possible, performance will
degrade



andy


-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of jonathan
Sent: Wednesday, May 27, 2009 12:44 AM
To: jQuery (English)
Subject: [jQuery] does selectors $ cache?


does selectors cache? for example, if I do $('#myid') twice, does it search
through the document twice for myid?




[jQuery] Re: does selectors $ cache?

2009-05-26 Thread scoob...@gmail.com

I don't think it does.. If you did $('div#myid') then it would search
through all the div's.. Here's a bit on jquery performance that I read
about..

http://www.artzstudio.com/2009/04/jquery-performance-rules/

Hope that helps...

On May 26, 10:44 pm, jonathan topcod...@gmail.com wrote:
 does selectors cache? for example, if I do $('#myid') twice, does it
 search through the document twice for myid?