1

Suppose I press the Tab key, I would want that it performs another action besides the default event. I've selected a text box and I want it to add some spaces (Just wanting a textarea to act like a text editor). How to trigger this type of event?

So far, I only know how to prevent the default action:

 $('#content').on('keydown', function(e) { if(e.which == 9) { e.preventDefault(); }}); 

But how do you fire another keyboard event?

3
  • 1
    Like this -> jsfiddle.net/x4jXg Commented Jan 18, 2014 at 22:07
  • This is concatenating the spaces, therefore the spaces are being found at the end of the whole textarea. Commented Jan 18, 2014 at 22:10
  • Yes, if you want to add the spaces at the caret, that's not really hard to do, there are hundreds of answers on SO on how to do that. Commented Jan 18, 2014 at 22:12

1 Answer 1

1

There is no need to preform any action. Just change value manually: LIVE DEMO

$('#content').on('keydown', function(e) { if(e.which == 9) { var val = $(this).val(); val += ' '; $(this).val(val); e.preventDefault(); }}); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.