[jQuery] Re: find is finding what?

2007-06-12 Thread Trans



On Jun 11, 7:30 pm, Erik Beeson [EMAIL PROTECTED] wrote:
 jQuery always returns a jQuery object, regardless of whether it finds
 anything or not. To see if anything has been selected, use last.length or
 last.size() being greater than 0. This is by design so chaining won't break
 if nothing is selected:

 $('.someSelector').addClass('highlighted');

 Will add the class to the selected stuff, if anything is selected.
 Otherwise, it doesn't do anything.

Ah, of course. That makes lots of sense. Thanks for the tip.

T.



[jQuery] Re: find is finding what?

2007-06-11 Thread Erik Beeson

jQuery always returns a jQuery object, regardless of whether it finds
anything or not. To see if anything has been selected, use last.length or
last.size() being greater than 0. This is by design so chaining won't break
if nothing is selected:

$('.someSelector').addClass('highlighted');

Will add the class to the selected stuff, if anything is selected.
Otherwise, it doesn't do anything.

--Erik


On 6/11/07, Trans [EMAIL PROTECTED] wrote:



Hi, I have the following:

var stack = $('#mydiv')
var last = stack.find('.card:last-child');

It doesn't make sense to me, b/c even if stack has no children, last
is being assigned to some object irregardless of the '.card' filter.
To work around I had to do this next:

if (last.is('.card')) {
  return last;
} else {
  return null;
};

What am I misunderstanding?

Thanks,
T.