One more reply for good measure ...

Using jQuery.each will provide you the isolation you need to make your
original code work.

jQurey.each( [0,1,2,3,4], function(index, num) {
    $("#port"+num).click(function() { bigchart(num); });
});

You should also be able to write it like this:

for ( i=0;i<5;i++ ) {
    (function(num) {
        $("#port"+num).click(function() { bigchart(num) });
    })(i);
}

However I'd suggest using one of the other example posted here. :)

--
Brandon Aaron

On Jan 30, 2:10 pm, timothytoe <[EMAIL PROTECTED]> wrote:
> I think I submitted a half-done version of this message by accident a
> few minutes ago. Sorry.
>
> This works:
>   $("#port0").click(function() {bigchart(0)});
>   $("#port1").click(function() {bigchart(1)});
>   $("#port2").click(function() {bigchart(2)});
>   $("#port3").click(function() {bigchart(3)});
>   $("#port4").click(function() {bigchart(4)});
>
> I try to roll it up like this:
>   for (i=0;i<5;i++) {
>     $("#port"+i).click(function() {bigchart(i)});
>   }
>
> But the closure gets me. When the function is called, i is 5 for any
> of the buttons.
> What is the elegant solution here?

Reply via email to