Skip to content

Instantly share code, notes, and snippets.

@wesinator
Last active June 10, 2021 14:47
Show Gist options
  • Save wesinator/68f6318ecb82909661b88852e0e359d5 to your computer and use it in GitHub Desktop.
Save wesinator/68f6318ecb82909661b88852e0e359d5 to your computer and use it in GitHub Desktop.
jquery way of getting cursor current position (`selectionStart`), without hardcoding element ID. https://www.geeksforgeeks.org/how-to-insert-text-into-the-textarea-at-the-current-cursor-position/
/*
https://www.geeksforgeeks.org/how-to-insert-text-into-the-textarea-at-the-current-cursor-position/
https://stackoverflow.com/questions/4069982/document-getelementbyid-vs-jquery
*/
$(e.selector)[0].selectionStart
// use selectionEnd to get delta of selected text
$(e.selector)[0].selectionEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment