Getting the next character after window.getSelection ()

Is there a way to get the next character after window.getSelection ()? I need to check if the character after the selected text is a space or not ...

EDIT: Thanks for your answers! I mainly use this link to highlight text, but would like to limit all words. I used the solution presented below (by Stephen) as a starting point; I think the following should work:

sel = window.getSelection(); var text = sel.anchorNode.nodeValue; var index = sel.baseOffset + sel.focusOffset-1; var isSpace = text[index] === undefined; if (isSpace) { alert("space"); } 

(In the link above, I used this code immediately after calling makeEditableAndHighlight).

+4
source share
2 answers

This is the beginning if there is another symbol in focus:

 window.getSelection().focusNode.textContent.charAt(window.getSelection().focusOffset) 
+2
source

Try it like this:

 var sel = window.getSelection() var text = sel.anchorNode.nodeValue; var index = sel.baseOffset + sel.focusOffset; var isSpace = text[index] === ' '; 
+1
source

Source: https://habr.com/ru/post/1482758/