how to get the node surrounding the cursor? #1351
Answered
by
Alex-D
philippehenri
asked this question in
Q&A
-
Hello, I have a text: aaaa bbb ccc I would like to know if it is possible to get the span surrounding the cursor (when a left or right key is pressed for example)? thanks |
Beta Was this translation helpful? Give feedback.
Answered by
Alex-D
Jan 15, 2023
Replies: 2 comments
-
Try something like: let selectedNode = document.getSelection().focusNode
while (['SPAN'].indexOf(selectedNode.nodeName) < 0) {
selectedNode = selectedNode.parentNode;
}
// selectedNode contains the first parent node you want Inspired from: Lines 1289 to 1313 in f5f921c |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Alex-D
-
thanks Alex ! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try something like:
Inspired from:
Trumbowyg/src/trumbowyg.js
Lines 1289 to 1313 in f5f921c