Possible Duplicate:
jquery select iframe children
I have many frames in my asp.net website. Since I don’t know its layout and I need to update a <span> value in a diferent diferent frame where my jquery code is, I do the following:
$('#myspan').text('sometext');
but anything changes. So I don’t know if it’s because jquery didn’t manage to catch the element with this selector because is not in its scope or why.
However this:
alert($('#myspan')); it shows an alert with [object][object] as result.
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#myspaninside it with this: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:
or