Skip to content

Instantly share code, notes, and snippets.

@tallykatt
Forked from dougalcampbell/tabifytextareas.js
Created July 25, 2016 02:01
Show Gist options
  • Save tallykatt/ea6290195c128316fe19c5762ef65ea7 to your computer and use it in GitHub Desktop.
Save tallykatt/ea6290195c128316fe19c5762ef65ea7 to your computer and use it in GitHub Desktop.
Bookmarklet: allow tabs in textareas (requires jQuery) Create a toolbar bookmark with this code. Click it when you want to be able to use tabs in a textarea.
javascript:$(document).delegate('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; $(this).val($(this).val().substring(0, start) + "\t" + $(this).val().substring(end)); $(this).get(0).selectionStart = $(this).get(0).selectionEnd = start + 1; }});void(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment