[jQuery] What is the canonical way of seeing if a selector returns an empty list?

2009-12-17 Thread Joe Grossberg
I understand that the way to see if there are any elements on the page with the class of "foo" is this: $('.foo') On a page with such elements, I will get a result like: jQuery(p.foo, p.foo) and if there are no matching elements, I will get jQuery() -- or at least that's how it's displayed in Fire

Re: [jQuery] What is the canonical way of seeing if a selector returns an empty list?

2009-12-17 Thread Charlie Griefer
On Thu, Dec 17, 2009 at 7:32 AM, Joe Grossberg wrote: > Instead, I do it like this (since zero is false-y in JavaScript): > > if ( $('.foo').length ) { > alert('at least one matching element'); > } else { > alert('nothing matches'); > } > > But is that the preferred way of doing this? > As far