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 variables.
On Jul 21, 8:51 pm, north <ollo...@web.de> wrote: > Hi, > > I just created a little widget using jQuery. The code is kinda ugly, > but I'm trying to improve it at least a bit. The first thing I wanted > to do was to cache the jQuery objects. In this case I created global > variables for this. > > Besides the global variables, I have a couple of functions using > "live" to bind a handler to an mousedown or click event. > > Now, when trying to use the variables in those functions I recognized > two "effects": > > 1. > Trying to apply .attr('disabled': true) to one of the cached objects > doesn't work, while applying other attributes seems to work fine. > > 2. > When defining a new variable in one of the functions, and trying to > use one of the global ones in it, it also doesn't seem to work > (something like this: var seriesAjaxOptions = $seriesAjax.html(); - > $seriesAjax being a cached object). > > Any idea what's going on (or what could be going on) here? > > Thanks!