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.

live example

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

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -