Welcome to the wonderful world of "closures" (which "double" as "functions" in JavaScript), you've been using them already (perhaps without know it) :).
The setTimeout function will actually take a function rather than a string (which it then 'eval's): function someFunction( obj ) { var message = obj.find('#message'); setTimeout( function() { message.fadeOut( 'slow', function() { $(this).remove(); } ); } , 5000 ); }; Some further reading on the subject of closures (the first few links from a Google search for "javascript closures"): http://www.jibbering.com/faq/faq_notes/closures.html http://blog.morrisjohns.com/javascript_closures_for_dummies Karl Rudd On Fri, Feb 22, 2008 at 6:20 AM, AsymF <[EMAIL PROTECTED]> wrote: > > For instance, say a function is passed an object and that function is > supposed to set an event to fire on a timeout, how would I do it? Even > more complicated, how would I do it if I needed to perform the action > on a sub-selection of the object passed? > > If I wanted to do this and I have just id's, then I could do the > following: > setTimeout("$(#'" + obj.id + " #message').fadeOut('slow', function () > {$(this).remove();});", 5000); > > But what if the object passed doesn't have an id? >