Skip to content

Instantly share code, notes, and snippets.

@takuyan
Created October 10, 2014 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takuyan/d0697729daff3138ed29 to your computer and use it in GitHub Desktop.
Save takuyan/d0697729daff3138ed29 to your computer and use it in GitHub Desktop.
# require https://github.com/ichord/Caret.js
$target = $('#post_body')
insertText = "Hello World"
text = $target.val()
position = $target.caret('pos')
newText = text.substring(0, position) + insertText + text.substring(position)
$target.val(newText)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment