I have an input field with comma separated values. I want to get the text between commas so that I can add a suggestion for each element. I found that I can get the cursor position using the value of the first child, how do I get only the text between commas?
Edit: split will get value of an array, but I wish to know which word my cursor is on (between the commas). firstChild.nodevalue gives me the caret position. I would like the word at the caret position. Example: apple, orange, banana … if my cursor was between the o and the range, it might give the suggestion orange, oranges, etc. If I somehow can get a function to return “orange” if my cursor is somewhere on the word, then I can compare it to a suggestion array.
This should do the trick…