Q: How to trigger event when val is changed from onkey event?
Problem: When change one input, other will change value, but don't change css.
JsFiddle: http://jsfiddle.net/6Qnbh/
$('.stat').val(0); $(".stat").change(function () { var val = $(this).val(); if (val > 0) { $(this).css("border", "1px solid #0f0"); } else if (val < 0) { $(this).css("border", "1px solid #f00"); } else { $(this).css("border", "1px solid #000"); } }).trigger("change"); /**/ $('.stat').keyup(function () { var val = $(this).val(); if (val > 0) { var num = Math.abs(val) * -1; } else { var num = Math.abs(val) * 1; } $('input[data-id=' + $(this).attr("data-link") + ']').val(num); });
changeevent is by default only send if the user directly changes the element. This is a design decision that should prevent endless loops if you e.g. fix the value upon user input. It could also have been handled in the specs by marking, if the event was triggered by user or by code, but the decision was that those events are exclusively fired on user interaction, and you need to decide yourself if you want to fire an event yourself when you change the value.