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 :: tolocalestring javascript currency fixing 2 decimal places 
Javascript :: iife javascript 
Javascript :: js looping through array 
Javascript :: javascript check if url returns 200 
Javascript :: count down timer in react native 
Javascript :: jquery chek radio 
Javascript :: make form submit on new tab using jquery 
Javascript :: js how to check is array empty es6 
Javascript :: add array to array javascript 
Javascript :: define an unsigned int js 
Javascript :: checkbox jquery checked 
Javascript :: how to make a div appear onclick 
Javascript :: js undici fetch data 
Javascript :: Find the maximum number in a jagged array of numbers 
Javascript :: scroll to top 
Javascript :: find by array of ids mongoose 
Javascript :: run function once javascript 
Javascript :: date masking javascript to not allow / 
Javascript :: dynamodb get all items nodejs 
Javascript :: moment get day 
Javascript :: node filesystem change directory of a file 
Javascript :: wait js 
Javascript :: react render after fetch 
Javascript :: discord chatbot 
Javascript :: how to use axios get 
Javascript :: javascript sum table row values 
Javascript :: mapbox remove marker 
Javascript :: jquery option not disabled 
Javascript :: list of higher-order functions javascript 
Javascript :: ISS proxy express 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =