Yes, it was a closure. I'm catching on. Problem solved. On Apr 13, 2:46 pm, "Daemach" <[EMAIL PROTECTED]> wrote: > I ran into a problem with code in one frame trying to operate on an > element in another frame last night that turned out to be caused by > the target DOM not being ready when I ran the selector. I created a > quick jq plugin that acts like $(document).ready() to run functions > when the target frame's DOM is ready and it works quite well. The > only beef I have with it is that I have to add a target frame context > to every selector now. While that's not a big deal, it would be much > cooler if I could add those functions to the target frame's DOM and > run them remotely, so any selectors that I pass the frameReady > function would run in the target frame's context by default. Well, it > ain't working as I had hoped, of course. I'm assuming it's a closure > problem but I'm not certain how to identify or solve it. > > Can one of you masters lend me some insight here? Any other ideas to > improve on this would be great as well. And, by the way, if the > functions below look suspiciously like code you've seen in an > outstanding advanced javascript coding book there is a reason for > that.... > > Here's a test page:https://beta.missionincrease.org/jquery/frametest.cfm > > The call in my document: > > $.frameReady(function(){ > alert(window.name); > > },top.mainFrame,true); > > ========================================= > > jquery.frames.js: > > jQuery.frameReady = function(f,k,r) { > var fr; > var ifr; > r = r || false; > > if (r) { > if (typeof k.jQuery.frameReady == "undefined"){ > k.jQuery.frameReady = jQuery.frameReady; > k.jQuery.isFrameReady = jQuery.isFrameReady; > } > fr = k.jQuery.frameReady; > ifr = k.jQuery.isFrameReady; > } else { > fr = jQuery.frameReady; > ifr = jQuery.isFrameReady; > } > > if (fr.done) { return f(); }; > > if (fr.timer) { > fr.ready.push(f); > } else { > fr.ready=[f]; > if (typeof addEvent !== "undefined") > { addEvent(window,"load",function(){ ifr(k,r); }); }; > fr.timer = setInterval(function(){ ifr(k,r); },13); > } > > } > > jQuery.isFrameReady = function(k,r){ > var fr; > > if (r) { > fr = k.jQuery.frameReady; > } else { > fr = jQuery.frameReady; > } > > if (fr.done) { return false; }; > > c = k.document || document; > > if (c && c.getElementsByTagName && c.getElementById && c.body) { > clearInterval(fr.timer); > fr.timer = null; > > for (var i=0; i<fr.ready.length;i++){ > fr.ready[i](); > } > fr.ready = null; > fr.done=true; > }; > > }