js tab in textarea

Solutions on MaxInterview for js tab in textarea by the best coders in the world

showing results for - "js tab in textarea"
Sophie
13 Jan 2016
1document.querySelector('#textarea').addEventListener('keydown', e => {
2	if ( e.key === 'Tab' && !e.shiftKey ) {
3		// execCommand operations are "Cmd|Ctrl+Z"-able
4      	// note: execCommand is deprecated and may not work in the future
5		document.execCommand('insertText', false, "\t");
6		e.preventDefault();
7		return false;
8	}
9});