jquery - Simple onkeydown + length count -
i have simple function here:
$('#input').keydown( function(e) { if( $(this).length === 8 ) { alert('we have winner!'); } else { return false; } });
it not work. why? appreciated.
assuming want check length of value of #input
, want:
$(this).val().length
instead of $(this).length
. may want rid of return false;
prevent being entered input field.
see updated fiddle here.
on separate note, work when there 8 characters in field, , key pressed. may way intended it, think may want keyup
event instead.
Comments
Post a Comment