> From: Adam Skinner
>
> I'm trying to reference an element from within an iframe.
>
> The following normal javascript code works:
>
> var iframeDoc = window.frames[iframeName].document;
> var data = iframeDoc.getElementById(iframeElement);
>
> I'm trying to jqueryize the "data" variable as follows (using
> the actual element id name for the time being):
>
> var d2 = $("#inside_iframe_element",iframeDoc);
>
> This just yields [], however. How do I refer to an element
> within the iframe?
Take a look at the code that handles the # selector in jQuery and you will
see why this doesn't work:
if ( m[1] == "#" ) {
// Ummm, should make this work in all XML docs
var oid = document.getElementById(m[2]);
r = ret = oid ? [oid] : [];
t = t.replace( re2, "" );
} else {
It's using a hard coded document.getElementById() instead of using the
document you provide.
The best way to work around this for the moment would be to continue to use
your own iframeDoc.getElementById() call but simply wrap the result in a
jQuery object:
var d2 = $( iframeDoc.getElementById(iframeElement) );
If you're doing a lot of these, of course it would make sense to wrap it up
in a function:
function $frame( doc, id ) {
return $( doc.getElementById(id) );
}
And then you could use:
var d2 = $frame( iframeDoc, iframeElement );
-Mike
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/