I am trying to insert four spaces when the tab key is pressed. I used the following code (see spaces = "\t" ), but when I switch it to spaces = " " , only one place is inserted when I click the tab. I also tried "+" "+" "+" ":
$(function () { $('textarea').keydown(function(e) { var keyCode = e.keyCode || e.which; if (keyCode == 9) { e.preventDefault(); var start = $(this).get(0).selectionStart; var end = $(this).get(0).selectionEnd;
NOTE. This is needed to insert spaces in the browser-based / ide text area.
source share