Menu
Sites
Language
event.preventDefault() not working

Hi,

I'm trying to limit the number of character a user can type in a contenteditable=true div;
 
I've bound a handler on keydown event to check the size of the typed text.
 
The code works fine on the simulator but not on the device.
 
HTML : 
<div class = "center" contenteditable = "true" style = "padding-top: .5vh" id = "name"></div>

JS :

$( "#name" ).bind(  "keydown", function( e ) {
      if( e.which !== 8 && $( this ).text().length >= 16 ) {
        e.preventDefault();
        return false;
      }
      return true;
});

 

Regards,

Edited on 18 03, 2014

Responses

4 Replies
talari praveen kumar
hi enoal i tried with your code it is working fine in sdk2.2b kindly let me know which sdk you are using??
Hi, I'm using sdk 2.1
talari praveen kumar
hi can you please check it in 2.2
I'll wait for the official 2.2 release thanks