You want keyup here, update based on comments :
$(document).ready(function() { $('.field').live('keydown', function(){ $(this).addClass('active'); }).live('keyup', function() { $(this).toggleClass('active', $(this).val() != ''); }); });
Your .live() starts correctly, but .val() does not change until there is a keyup , keydown fires before the value is updated, so your if() will not be true until the second key is pressed.
source share