How do I bind click event on dynamic generated buttons in backbone.js?
window.PackageView = Backbone.View.extend({
tagName: "div",
className: "package-template",
events:{
'click #display-nodes' : 'main', // This button is declared in my HTML code and calls main method successfully.
'click .display' : 'disp', // This is dynamic button generated with class as display
},
getAction: function(nodeId){ // Get Actions from NodeId and generate buttons
$('.nodes').append("<button>" + action.Name + "</button>"); //Generate Buttons
$(".nodes button").addClass("display");
},
disp: function(){
alert("Inside Disp Function");
},
On clicking #display-nodes
the nodes are displayed as required but .display
is not working. How do I make this button call the function?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…