Espen Espen - 1 year ago 56
jQuery Question

Is it possible to find from what value a .change() was triggered?

From a

tag, is it possible to find from what value the
was triggered?

Answer Source

Use a variable for cache the previous value.

// bind change event handler to the eleemnt 
// and cache the current value in `prev`
var prev = $('#test').change(function() {
  // get previous value from `prev`
  console.log('prev : ' + prev + ' , current : ' + this.value);

  //... do the rest here

  // update the `prev` variable with current value
  prev = this.value;
}).val(); // get the default value
<script src=""></script>
<select id="test">
  <option value="1">1</option>
  <option value="11">11</option>
  <option value="111">111</option>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download