 <p>This will return true for elements that are currently in the document, and selectors which match elements in the document.</p> <pre><code>function isInDoc(sel) { var $sel = jQuery(sel); return $sel.length &amp;&amp; jQuery.contains(document.documentElement, $sel[0]); } </code></pre>