jQuery live keydown doesn't register until second keydown
Posted
by Simon
on Stack Overflow
See other posts from Stack Overflow
or by Simon
Published on 2010-04-09T17:59:00Z
Indexed on
2010/04/09
18:03 UTC
Read the original article
Hit count: 326
jQuery
Hi there,
I'm trying to add a class (.active) to a text field once the user starts typing. I got it to work somewhat with the following code, but for some reason the .active class is not applied immediately when the user starts typing, it's only applied after a second letter has been typed. Any ideas?
$(document).ready(function() {
loginField = $('.field');
loginField.live('keydown', function(){
if ($(this).val()){
$(this).addClass('active');
}
});
});
© Stack Overflow or respective owner