views:

55

answers:

2

Say I do

var s = $('#something');

and next I want to test if jQuery found #something, i.e. I want to test if s is empty.

I could use my trusty isempty() on it:

function isempty(o) {
    for ( var i in o )
        return false;
    return true;
}

Or since jQuery objects are arrays, I suppose I could test s.length.

But neither seem quite in the idiom of jQuery, not very jQueryesque. What do you suggest?

+5  A: 

Use s.size() or the s.length property.

http://api.jquery.com/size/

Billiam
I'd say `.size()` is definitely the most jQueryesque of the options. Though I dare say `.length` would be faster. Thank you.
fsb
A: 

Thought I remembered this being asked before. Here is the SO link.

Peter J