Dynamic Event Listeners
This example puts into practice the methodology outlined here: https://docs.google.com/document/d/1VGUL0RzezbeMhrB6rbD5I8FBOpLhrezl8S_XN3Cp06g/edit
by kshep92
JavaScript
$(document).ready(function() {
for(i=0; i<5; i++) {
btn = $("<button />", { text: "Create a button", click: function() {
$masterButton = $(this);
btn2 = $("<button />", { text: "Change parent button text", click: function() { $masterButton.text("Changed!"); } });
$("body").append(btn2);
}
});
$("body").append(btn);
}
});