JSFiddle - React, Tailwind, and code Playground
by webvitaly
HTML
<form>
<input type="text" placeholder="type here to test events...">
<div class="log">log of change and keyup events. </div>
</form>
CSS
form { padding: 10px; }
JavaScript
$(function(){
$('form input').data('val', $('form input').val() ); // save value
$('form input').change(function() { // works when input will be blured and the value was changed
// console.log('input value changed');
$('.log').append(' change');
});
$('form input').keyup(function() { // works immediately when user press button inside of the input
if( $('form input').val() != $('form input').data('val') ){ // check if value changed
$('form input').data('val', $('form input').val() ); // save new value
$(this).change(); // simulate "change" event
}
});
});