$(selector) never returns a null or undefined, even if that selector does not match any element on a given page.   any empty array of elements is returned instead.  

check for length > 0 instead.