> Is there a way to set a variable in an each that will be stored 
> separately for each instance of the plugin (for example, if I am 
> performing an action on all <input>s, is there a way to store the 
> input type and reuse it later?). Maybe I'm not being clear, so
> here's the example:
>
>                 $(".slider").each(function() {
>                     rangeEl = $(this).siblings().filter("input.range");

You haven't put the keyword "var" in front of rangeEl (and the others), so
that creates a global variable; as you noted it's clobbered each time
through the function. If you say "var rangeEl" it will be a local variable
and you'll get a different one each time the function is called, creating a
closure that your $(this).Slider() plugin can use.

My experience is that 99 out of 100 times you want to say "var" anywhere you
first start using the variable. Say it early and say it often--Javascript
doesn't mind if you say it more than once in the same function. That
especially applies to for-loop variables.  Every for loop should start with
"for ( var" or it's most likely broken in a very dangerous way.



_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to