e.preventDefault()
would help. If you want to add twelfe spaces without literally typing them, use Array(12).join(" ");
. Surely, typing twelfe spaces may be easier.
Some methods to type twelfe spaces:
var s=[];s.length=12;s.join(" ");
var s=Array(12).join(" ");
var s=" "; //Shortest so far.
As you can see, using Array(i).join(" ")
starts being useful when i
is higher than 17. Note that the this approach enables a dynamic indenting feature.
EDIT
Quick tuturial on key events:
keydown
- Initiated when the key is pressed down. This event is fired once, before any default event has occured
keypress
- This event is fired (multiple times) while the key is pressed down, before a default event has occured.
keyup
- Fired after the key has been released (which happens only once per set of key events). Needless to say, all of the default events have already been occured.
keydown
and keypress
can be used to capture and cancel key events. If you want to catch and validate all key events, use keypress
. If you've assigned multiple events (eg to window
and to input
), you may also use e.stopPropagation()
in conjunction with e.preventDefault()
. The first function stops the event from bubbling further (=the event isn't passed to other event listeners any more). The second function prevents the default behaviour from occuring.