JavaScript get word before cursor
问题 Okay, I've been looking all over the web to find a solution but I couldn't find one, is there a way to get the word before the caret position in an editable div so a bit like: This is some| demo texts This should return the word "some"... I don't know if this is possible, I would be glad for any help, thanks :). 回答1: With using Caret Position finder method provided here this will do what you want. function ReturnWord(text, caretPos) { var index = text.indexOf(caretPos); var preText = text