jquery - detect if selector returns null
        Posted  
        
            by peirix
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by peirix
        
        
        
        Published on 2009-05-28T10:46:47Z
        Indexed on 
            2010/03/24
            4:03 UTC
        
        
        Read the original article
        Hit count: 358
        
jQuery
|best-practices
What is the best way to detect if a jQuery-selector returns an empty object. If you do:
alert($('#notAnElement'));
you get [object Object], so the way I do it now is:
alert($('#notAnElement').get(0));
which will write "undefined", and so you can do a check for that. But it seems very bad. What other way is there?
© Stack Overflow or respective owner