The only thing you need to do is to capture the number on a scope.
Like this:

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

And voila, you can also do:

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

Hope that helps
Cheers

Ariel Flesler


On 30 ene, 23:28, Feijó <[EMAIL PROTECTED]> wrote:
> I'm yet to be an expert in jQuery :)  But I would solve that like this:
>
>   $(".port").click(function() {bigchart($(this).attr('port-id') )});
>
> now in your html code, I guess its like:
>
>     <div id=port1>
>
> change to
>
>     <div class=port port-id=1>
>
> Feijó
>
> timothytoe escreveu:
>
>
>
> > 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?- Ocultar texto de la cita -
>
> - Mostrar texto de la cita -

Reply via email to