Test for empty jQuery selection result

Posted by fsb on Stack Overflow See other posts from Stack Overflow or by fsb
Published on 2010-04-15T22:10:22Z Indexed on 2010/04/15 22:13 UTC
Read the original article Hit count: 307

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript