jQuery selectors are only instructions processed by other functions.. so it depends on what you're doing. In this case you would be creating one less jQuery object and that can be significant less overhead.
On Dec 11, 5:32 am, nachocab <[EMAIL PROTECTED]> wrote: > Thanks Richard, > That's a great refactoring. I need to harness the power of selectors > and stop relying on functions so much. Do you think it depends on the > case or that selectors beat functions in terms of performance? > > On Dec 10, 7:10 pm, ricardobeat <[EMAIL PROTECTED]> wrote: > > > You can shorten that to: > > > if ( !$('#phrases li.active').is(':first-child') ) { > > > On Dec 10, 12:47 pm,nachocab<[EMAIL PROTECTED]> wrote: > > > > Thanks Richard! > > > You saved my life :-) > > > > On Dec 10, 2:36 pm, "Richard D. Worth" <[EMAIL PROTECTED]> wrote: > > > > > You're comparing two different (ie non-equal) jQuery objects that > > > > happen to > > > > contain (in an array-like fashion) the same DOM Element. If you want to > > > > compare those two DOM Elements, change > > > > > $("#phrases").find("li.active") != $("#phrases").find("li:first") > > > > > to > > > > > $("#phrases").find("li.active")[0] != $("#phrases").find("li:first")[0] > > > > > - Richard > > > > > On Wed, Dec 10, 2008 at 3:05 AM,nachocab<[EMAIL PROTECTED]> wrote: > > > > > > Hi, > > > > > I have this html: > > > > > > <ul id="phrases"> > > > > > <li id="phrase_0" class="active">This is my first phrase</li> > > > > > <li id="phrase_1">This is my second_phrase</li> > > > > > </ul> > > > > > > And I wanted to do this comparison: > > > > > if ( $("#phrases").find("li.active") != $("#phrases").find > > > > > ("li:first") ) { > > > > > alert("the active list-item is not the first one"); > > > > > } > > > > > > The problem is the alert pops up, but in this case the first item is > > > > > clearly the active one. Can anybody figure out what's wrong? > > > > > > Thanks! > > > > > > Nacho