On Wed, Apr 20, 2011 at 3:22 PM, Tom de Koning <[email protected]>wrote:
> "find goes through all the descendants"
>
> descendants of what element? I don't see the difference
>
>
it's the difference between:
a) $(".foo.bar") // aka $("tr [name^='rowBatch'].shown")
and
b) $(".foo").find(".bar") // aka $("tr [name^='rowBatch']").find ('.shown')
The first case would find all elements that have both the "foo" and "bar"
class.
The second case would find all elements that have the "bar" class and are
descendants of elements that have the "foo" class.
_jason
On Wed, Apr 20, 2011 at 2:35 PM, Ravindran Navaneethan <
[email protected]> wrote:
> >>$allRows.find ('.shown').addClass("up");
>
> should be replaced with
>
> >>$allRows.filter('.shown').addClass("up");
>
> find goes through all the descendants whereas filter goes through the
> selected collection. Give it a try.
>
> On Apr 20, 4:25 am, Brams <[email protected]> wrote:
> > Hello,
> >
> > I've been reading up a lot on enhancing JavaScript code as well as
> > utilizing JQuery in a proper manner. I tried to implement some of the
> > techniques that I saw in order to see what performance gain i would
> > get. I tried something out and i was sure that the change would
> > enhance performance but it didn't. I just want to know if there's
> > something that I'm missing:
> >
> > My Code before (The code below took around 90 ms to execute):
> > ------------------------
> >
> > $("tr [name^='rowBatch'].shown").addClass("up");
> > $("tr
> > [name^='rowBatch']").not(':first').not(".shown").removeClass("notshown");
> >
> > My Code after (The code below took around 350 ms to execute)
> > ---------------------
> >
> > var $allRows = $("tr [name^='rowBatch']");
> > $allRows.find ('.shown').addClass("up");
> > $allRows.not(':first').not(".shown").removeClass("notshown");
> >
> > What I don't understand is the increase in execution time! by caching
> > into a local variable, I'm now traversing the DOM only once instead of
> > twice. Is the 'find' or 'not' methods slowing things down? In your
> > opinion, how can the code above be optimized.
> >
> > Thanks a lot!
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]