Saturday, April 20, 2019

javascript - jQuery .on() does not trigger any events





I am writing an application using jQuery, where when a button is clicked, a select box is generated and appended to a row. Whenever the select changes, it should trigger the change event, but using .on("change", function() {}); isn't working:



Code:






HTML5-Template















Any idea's what I'm doing wrong?


Answer



As $(".member-type") is empty when you do the binding, you're not doing anything.



Change



$(".member-type").on("change", function() {
alert("changed");
});



to



$(document).on("change", ".member-type", function() {
alert("changed");
});


or this because the #Container element is static:




$("#Container").on("change", ".member-type", function() {
alert("changed");
});

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...