select handler in jQuery

by hellosze

HTML

<form>
  <input class="target" type="text" value="Field 1" />
  <select class="target">
    <option value="option1" selected="selected">Option 1</option>
    <option value="option2">Option 2</option>
  </select>
</form>
<div id="other">
  Trigger the handler
</div>
The event handler can be bound to the text input and the select box:

JavaScript

$('.target').change(function() {
  alert('Handler for .change() called.');
  alert($(this).attr("value"));
});