I am generating buttons with jQuery using:
var button_a = $("<button />", {
text: 'A',
click: do_something,
class: "button a"
});
var button_b = $("<button />", {
text: 'B',
click: do_something,
class: "button B"
});
function do_something(){
alert("Button Was pressed");
}
I would like to make it so do_something instead do:
function do_something(name){
alert("Button " + name + " was pressed");
}
How could I change the jQuery button creation so that I could pass in a name to the click: do_something?
Is the only solution to create a closure before hand?