On Oct 15, 8:42 am, JenniferWalters <jenniferwalt...@email.com> wrote:
> I do agree on smaller DOM trees, a user really is not able to tell the
> difference and jQuery is so much easier to code.

What Michael and James are trying to tell you is that the jQuery
selector for ID (eg. $('#myID')) actually uses document.getElementById
('myID')
That's one of the first things it checks for.

Even on a huge page, this should not make a notable difference.
Well, unless you have all sorts of different selectors, mainly ones
that are not ID-related AND you are doing it in a non-optimised way,
such as multiple calls to the same element insead of referecing it:

Slow:
$('#myID').hide();
$('#myID').find('a').click(function(){ $('myID').show(); });

Fast:
var $myID = $('#myID');
$myID.hide();
$myID.find('a').click(function(){ $myID.show(); });

Notice that in the Fast example you are only doing 1 call to the DOM,
while in the Slow example you have 3 calls to the same object, thus
mkaing you code up to 3 times slower (for the non-optimised code, the
find('a') will perform the same).

The beauty here is that you can use all sorts of CSS selectors
(including element relationships) which the default DOM does not have
access to.

Reply via email to