The onchange
event only fires when the element loses focus, that is, when it blur
s with a different value
than when it gained focus
.
I'm not aware of any native listener that would provide such functionality in real time, but you could try maneuvering jQuery's .data()
method to store the current value and check against it in a standard keyboard event, such as keyup
:
$('#product_descriptioncontent').children().each(function() {
$(this).on('keyup', function() {
if ($(this).data('c_val') != $(this).val()) {
alert('value changed!');
//do other stuff
}
$(this).data('c_val', $(this).val());
}).data('c_val', $(this).val());
});
JSFiddle
Note that you may also remap the keyup
to multiple events for extra checks:
$(this).on('keyup mouseup blur', function(){
As well as simply calling $('#element').keyup()
will trigger the on
function for that element, if you ever need to call it without the user inputting anything. =]
Note that the .on()
jQuery method is only supported in jQuery 1.7+, for older versions you should use .live()
.