> > if ($('#someID')) { > // something matched the selector > } See, and there you go making a wrong assumption that beginners are much more likely to run into. !![] is evaluating to true and so is a jQuery object that has not matched any items. I'm not blaming you for it, it's counter-intuitive (if you don't know objects always evaluate to true) but that's how JS works. So an exists() function could could probably help people avoiding this mistake.
(Your other example where using [0] is a workable solution however) -- Felix -------------------------- My Blog: http://www.thinkingphp.org My Business: http://www.fg-webdesign.de RobG wrote: > On Jul 10, 4:50 am, "Sean Catchpole" <[EMAIL PROTECTED]> wrote: > >> I believe that learning jquery returns an array like object is more >> useful than creating a .exists() function. >> > > It seems to me that the most common reason for testing if an element > exists is to use it later, so why not: > > var element; > if ( (element=$('#someID')[0]) ) { > /* element exists */ > } else { > /* damn... */ > } > > Another idea is that if the seletor doesn't select any elements, > return null (as does getElementById() in that case): > > if ($('#someID')) { > // something matched the selector > } > > but that may not be backward compatible. Of what use is an empty > jQuery object? > > > -- > Rob > > >