The jQuery function ($('someSelector')
) will always return an object, even if no elements match the selector.
If you really are using multiple frames, you have a problem: jQuery can't find elements across frames, only in the current document/frame – unless you pass a proper context object for the specific document you want to target.
For example, if you have an <iframe id="myframe">
, you can look for #myspan
inside it with this:
var frameDoc = $('#myframe')[0].contentWindow.document;
var mySpan = $('#myspan', frameDoc);
For that to work, the iframe's source must be hosted in the same domain as the main page. There's also the following cleaner options, suggested in the comments below:
var mySpan = $("#myframe").contents().find('#myspan')
or
var mySpan = $('#myspan', $("#myframe").contents());