In ContentEditable, how can I get a reference to the element immediately preceding the caret?
问题 I am trying to write a function that will, on keyup , give me a reference to the element immediately preceding the caret in a contentEditable div. If the caret is in a text node then the function should return null . If the caret is at the start of the contentEditable then the function should return null . But if the caret is at the start of a text node, and this text node is immediately preceded by an element such as a Span, then the function should return a reference to this element. And,