Re: [jQuery] Trouble with $(expr, context) and iframe documents

2006-12-12 Thread Klaus Hartl
Michael Geary schrieb:
 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.


Couldn't that be solved by using:

var oid = self.document.getElementById(m[2]);

Not tested, not sure...


-- Klaus

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Trouble with $(expr, context) and iframe documents

2006-12-11 Thread Jessica O'Donnell
Can someone please delete my email from this thing? I have tried to
cancel many times.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Adam Skinner
Sent: Monday, December 11, 2006 8:58 AM
To: discuss@jquery.com
Subject: [jQuery] Trouble with $(expr, context) and iframe documents


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?
-- 
View this message in context:
http://www.nabble.com/Trouble-with-%24%28expr%2C-context%29-and-iframe-d
ocuments-tf2794146.html#a7795126
Sent from the JQuery mailing list archive at Nabble.com.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Trouble with $(expr, context) and iframe documents

2006-12-11 Thread Michael Geary
 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
discuss@jquery.com
http://jquery.com/discuss/


Re: [jQuery] Trouble with $(expr, context) and iframe documents

2006-12-11 Thread Dave Methvin
 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?

The #id notation in a selector always uses document.getElementById; in your
case it's the wrong document (the document that contains the iframe, not the
document of the iframe). One workaround would be to select the object
manually when you create the jQuery object,
$(window.frames[iframeName].document.getElementById(iframeElement)), and I
agree it's ugly. Another shorter(text)/longer(runtime) way would be to use
the general attribute syntax, $([EMAIL PROTECTED], iframeDoc).
If you do the latter, it will be more efficient to use the actual tag type
(e.g, [EMAIL PROTECTED]) rather than *, which requires looking at every element
in the iframe.


___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/