PruitIgoe
PruitIgoe

Reputation: 6384

jquery: getting any change event on any form

I know I can get any change event on one form by using this code:

$("#testForm :input").change(function() {
console.log($(this).attr('name'));      
});

How would I get it if I have multiple forms?

Upvotes: 2

Views: 12721

Answers (3)

ayyp
ayyp

Reputation: 6608

Either do something like that which will get all changes to all form inputs, or give each separate form an ID.

$("form :input").change(function() {
console.log($(this).attr('name'));      
});

Upvotes: 4

ShankarSangoli
ShankarSangoli

Reputation: 69915

Try with tag selector

$("form :input").change(function() {
   console.log($(this).attr('name'));      
});

Upvotes: 2

Joseph Marikle
Joseph Marikle

Reputation: 78550

$("form :input").change(function() {
console.log($(this).attr('name'));      
});

for all forms, but if you still want only that one form

$("#testForm :input").change(function() {
console.log($(this).attr('name'));      
});

Upvotes: 3

Related Questions