Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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;
	}
});
 
PREVIOUS NEXT
Tagged: #js #tab #textarea
ADD COMMENT
Topic
Name
2+4 =