Reputation: 443
I want to track when a form changes, so I can do something based on the ID of the input that changed.
Currently, I am using this:
$( "#search" ).change(function() {
console.log('form has changed');
});
Really, I want to know WHICH input within that form changed. $(this.id) seems to get the form id "search" but is there a way to access the input id (without binding an change event to each input)
Upvotes: 2
Views: 4598
Reputation: 388436
You can get the input element using the event object
$("#search").change(function (e) {
console.log('form has changed', e.target.id);
});
Another solution is to bind the handler to the input elements itself like
$("#search :input").change(function (e) {
console.log('form has changed', this.id);
});
Upvotes: 13