Hey,

I'm trying to pass a function an array of buttons and function
pointers. What I want to do is to assign functions to the arbitrary
list of buttons. At the moment, I'm using:

                                if (button_text !== undefined){
                                        for (var vars in button_text){
                                                var button = $('<input 
type="button" value="' +
button_text[vars] + '">').appendTo('#content');
                                                button.data('idnum', vars);
                                                
console.log(button.data('idnum'));
                                                button.bind('click', 
function(e){ return_functions[$
(this).data('idnum')](); });
                                        }
                                }

and the reason I'm assigning data is because doing:
button.bind('click',function(e){ return_functions[vars]; })

always assigns the last function to all the buttons (presumably
because vars is iterated all the way through before the event is
called).

Is there a more elegant solution to this?

Thanks

Reply via email to