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:

<div id="my-widget">
   ....
</div>

$().ready(function(){
  // cache as a local var, everything inside this function
  // will have access to it
  var $widget = $('#my-widget');

  // save some data related to the widget
  $widget.data('options', {bla: 'bla'});

});

As always, showing the code you're talking about helps a lot in
getting good advice/answers.

cheers,
-- ricardo

On Jul 21, 7:51 am, 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!

Reply via email to