Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

on e.keycode == 9 (tab), add 12 spaces, and prevent default behavior

Tags:

jquery

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

like image 799
re1man Avatar asked Jul 13 '26 23:07

re1man


1 Answers

To catch the tab keypress, you would have to bind to the keydown event. When pressing tab, a keyup event is not triggered.

like image 97
Kevin B Avatar answered Jul 17 '26 16:07

Kevin B