The point is to get the first DOM node, so you'd still need to do [0], which would still throw an error if there was no match. If you're not certain that there'll be a match, maybe something like this would be safer:
var $foo = $('#foo'); if($foo.length > 0) { var foo = $foo[0]; } else { // no foo } I use $ to prefix variables that point to a jQuery object as a convention to remind myself that it's a jQuery object. --Erik On 8/16/07, R. Rajesh Jeba Anbiah <[EMAIL PROTECTED]> wrote: > > > On Aug 15, 11:29 am, pd <[EMAIL PROTECTED]> wrote: > > I've been hacking with jQuery on and off lately and I've now hit the > > annoying problem of not being able to access simple DOM 0 properties > > unless, apparently, using either of the following syntaxes: > > > > $('#foo')[0] > > Will throw error if there is no match, IIRC. > > > $('#foo').get(0) > <snip> > > Use $('#foo:nth(0)') instead. For just first match, you could use $ > ('#foo:first') > > > -- > <?php echo 'Just another PHP saint'; ?> > Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/ > >