2

Possible Duplicate:
Detect element content changes with jQuery

I have a div with a few text fields and radio buttons and text areas and i want to check if any of the content changed for example...i have

<div class="tools">
     //if any of the content changes in here can i find out
</div>

i have

 $('.tools').change(function(){
console.log("something changed");
});

and its not logging....so i need to loop or check content...any ideas

Community
  • 1
  • 1
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321

1 Answers1

3

You could possible do something like this.

$('.tools').find('input,textarea')
.each(function(){
     $(this).change(function(){
          console.log("Something changed");
     }
});

I did not test this, but it might help:-)

Phrogz
  • 296,393
  • 112
  • 651
  • 745
jcreamer898
  • 8,109
  • 5
  • 41
  • 56
  • That would require form elements to be placed in this element. But what if it isn't a form? – BoltClock Jan 11 '11 at 21:50
  • I believe with his example he was referring to elements inside of that div tools element. If it was not inside of the tools class, you could add a class to each one of the form elements throughout the page and do the each loop on that class. – jcreamer898 Jan 11 '11 at 21:53
  • You actually don't need the each() loop since most jQuery methods are written to work with multiple elements. – typeof Jan 11 '11 at 22:02