Question: When you say consider caching $('#inline_dialog') in a local variable, do you mean simply storing the string x = <somehtml> or another method of caching. How would you cache it and reuse it with jQuery? Does it need to be inserted into the document before it can be cached?
Thanks! Brook ________________________________________ From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Erik Beeson Sent: September 19, 2007 11:39 AM To: jquery-en@googlegroups.com Subject: [jQuery] Re: How to return a click event from the container function For that to happen, showDialog would have to block until the dialog was closed, and that's not how JavaScript works. To do what you want, pass a callback function to showDialog and call it on close. Something like this (untested): this.showDialog = function(msg, buttons, onHide) { $('#inline_dialog').show().swapDepths(); var buttons = (buttons) || '<div class="clear-block"></div><div id="inline_alert_close_button"></div>'; $('#' + self.window_id).floatWinSetContent({content:msg + buttons, title:''}); $('#inline_alert_close_button').click(function() { $('#inline_dialog').hide(); if($.isFunction(onHide)) onHide.call(/* whatever you want 'this' to be in your callback, maybe $('#inline_dialog') */); return false; }); } Also, you might consider caching $('#inline_dialog') in a local variable, since you call it a lot. Lastly, it's good form to include a semicolon after the last } since it's technically an assignment, so one should be there. It'll help save you from potential problems down the road. Good luck with it. --Erik On 9/19/07, Skilip <[EMAIL PROTECTED]> wrote: > > Hi, I'm currently working on a function which shows a inline dialog, > so I can use html in the dialog box. In the dialogbox I've put a > button to close the dialog box. If the button is clicked I want the > function showDialog() to return a value. The problem is that it's out > of the scope when I'm in the click() function. It there a solution? > > this.showDialog = function(msg, buttons) { > $('#inline_dialog').show().swapDepths(); > var buttons = (buttons) || '<div class="clear-block"></div><div > id="inline_alert_close_button"></div>'; > $('#' + self.window_id).floatWinSetContent({content:msg + buttons, > title:''}); > $('#inline_alert_close_button').click(function() { > $('#inline_dialog').hide(); > return false; > }); > } > >