Skip to content

Instantly share code, notes, and snippets.

@dougalcampbell
Created November 12, 2013 19:34
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dougalcampbell/7437263 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