[jQuery] Re: Caching jQuery objects

2009-07-21 Thread Ricardo
Instead of global variables, use the data() method to save all data in your container, and use local vars for cacheing. Let's say your widget looks like this: $().ready(function(){ // cache as a local var, everything inside this function // will have access to it var $widget = $(

[jQuery] Re: Caching jQuery objects

2009-07-21 Thread olsch01
I guess I could also create a global object, and then store all the variables and functions in there. But in this case it's not so important, because the widget will be the only content on the page and loaded into an iframe. On 21 Jul., 13:25, Jules wrote: > I found out that jquery.validate code

[jQuery] Re: Caching jQuery objects

2009-07-21 Thread Jules
I found out that jquery.validate code uses the form object to store global variables. Taking clue from the code, I uses the document object $.data($(document)[0], 'myData', myData). Not sure if this is the best practice, may be others can shed some light to the best practice to store global vari