I've had lots of fun(!!??) with setTimeout, especially in conjunction with objects.<br><br>setTimeout has 2 arguments:<br>* a string which is interpreted (effectively by an eval function) on expiry of the timeout.<br>* the timeout interval.<br><br>Because the first argument is treated as a string, it's very difficult to see what's being evaluated. Generally when I use setTimeout I:<br>* build the string in a variable so if I have problems I can use an alert to display it and check it.<br>* use the string as the 1st agrumentof setTimeout, e.g. setTimeout(myString, interval);<br><br>Also because the first argument is treated as a string, on expiry of the timeout the browser does not remember any object references ("this" or "myObj" which were valid at the time of the setTimeout call.<br><br>So in the simplest case you have to hardcode the actual name of the variable which contains the object reference in the function driven by the setTimeout call, e.g.<br>var myObj = new myObjType; // object constructor<br>setTimeout (myFunc, interval);<br>function myFunc(){<br> myObj.width = x;<br>}<br><br>If you want to use myFunc on a range of objects or to make the entire sequence of code which calls myFunc re-usable, things get trickier and you have to:<br>// Make the OBJECT on which myFunc operates a custom <br>// PROPERTY of a standard JS object, e.g.<br>var myObj = new myObjType;<br>document.ObjId = myObj;<br>// Create a function to call myFunc. All application code <br>// calls callMyFunc, never myFunc<br>function callMyFunc(newWidth, interval){ <br> var myString = "myFunc(" + newWidth + ", " + interval + <br> "";<br> // This where it's handy to be able to display myString <br> // if you're finding it difficult to get the punctuation <br> // right - especially if there are several arguments <br> // and / or some of the arguments are string values and <br> // have to be in single quotes.<br> setTimeout (myString, interval);<br>}<br>// Refer to the target object via the custom property of <br>// the standard object, e.g.<br>function myFunc(newWidth, interval){<br> // Here you have to use ObjId to find the required object<br> // see notes below.<br> document.ObjId.width = newWidth;<br>}<br>