Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js tab in textarea

document.querySelector('#textarea').addEventListener('keydown', e => {
	if ( e.key === 'Tab' && !e.shiftKey ) {
		// execCommand operations are "Cmd|Ctrl+Z"-able
      	// note: execCommand is deprecated and may not work in the future
		document.execCommand('insertText', false, "	");
		e.preventDefault();
		return false;
	}
});
Comment

add tab to textarea javascript

document.getElementById('textbox').addEventListener('keydown', function(e) {
  if (e.key == 'Tab') {
    e.preventDefault();
    var start = this.selectionStart;
    var end = this.selectionEnd;

    // set textarea value to: text before caret + tab + text after caret
    this.value = this.value.substring(0, start) +
      "	" + this.value.substring(end);

    // put caret at right position again
    this.selectionStart =
      this.selectionEnd = start + 1;
  }
});
Comment

tab adds tab textarea javascript

$(document).delegate('#textbox', 'keydown', function(e) {
  var keyCode = e.keyCode || e.which;

  if (keyCode == 9) {
    e.preventDefault();
    var start = this.selectionStart;
    var end = this.selectionEnd;

    // set textarea value to: text before caret + tab + text after caret
    $(this).val($(this).val().substring(0, start)
                + "	"
                + $(this).val().substring(end));

    // put caret at right position again
    this.selectionStart =
    this.selectionEnd = start + 1;
  }
});
Comment

tab in textarea javascript

$("textarea").keydown(function(e) {
    if(e.keyCode === 9) { // tab was pressed
        // get caret position/selection
        var start = this.selectionStart;
        var end = this.selectionEnd;

        var $this = $(this);
        var value = $this.val();

        // set textarea value to: text before caret + tab + text after caret
        $this.val(value.substring(0, start)
                    + "	"
                    + value.substring(end));

        // put caret at right position again (add one for the tab)
        this.selectionStart = this.selectionEnd = start + 1;

        // prevent the focus lose
        e.preventDefault();
    }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript regex number only 
Javascript :: remove undefined values from object javascript 
Javascript :: js get number from string 
Javascript :: js document.getelementsbyclassname modify innertext 
Javascript :: selectpicker append option 
Javascript :: javascript object toarray 
Javascript :: how to see if a web site is useing react 
Javascript :: javascript get domain 
Javascript :: the engine node is incompatible with this module 
Javascript :: jquery append once 
Javascript :: vuejs localstorage add value 
Javascript :: refresh page on back button click javascript 
Javascript :: javascript to mask email address 
Javascript :: node js random number generator 
Javascript :: jquery get today date 
Javascript :: title case a sentence-javascript 
Javascript :: moment check valid date 
Javascript :: detect fullscreen mode 
Javascript :: javascript set delay 
Javascript :: js canvas line end 
Javascript :: javascript capitalize first letter 
Javascript :: Get current active sheet name google appscript 
Javascript :: laravel 8 include javascript in blade 
Javascript :: jquery select radio by name 
Javascript :: javascript one off event listener 
Javascript :: jquery minified cdn 
Javascript :: javascript random letter generator 
Javascript :: getting the distance fo an element from the top jquery 
Javascript :: how to expand compressed js file vscode 
Javascript :: allow only letters in div javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =