Have a slight problem with this code :
jQuery.fn.markCursor = function(e){
$(this).focus();
$(this).keyup(function(e) {
$cursorStart.enterText(e);
});
};
jQuery.fn.enterText = function(e){
if (e.keyCode == 9){
$cursor.val("");
alert("hello");
}
};
The tab key is resorting to its default behavior in the browser, would .preventdefault help here? How would I add 12 spaces without the code taking up 12 lines in jquery :p
e.preventDefault()would help. If you want to add twelfe spaces without literally typing them, useArray(12).join(" ");. Surely, typing twelfe spaces may be easier.Some methods to type twelfe spaces:
As you can see, using
Array(i).join(" ")starts being useful wheniis 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 occuredkeypress– 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.keydownandkeypresscan be used to capture and cancel key events. If you want to catch and validate all key events, usekeypress. If you’ve assigned multiple events (eg towindowand toinput), you may also usee.stopPropagation()in conjunction withe.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.