I get the text node (node.nodeType == 3) returned from the getSelection range, for example:
var selectionRange = selection.getRangeAt(0); var startContainer = selectionRange.startContainer;
This startContainer is usually node text, like the following html:
<p>Paragraph in <u>parag</u>raph.</p>
The text node appears with the text "raph". if | indicates a choice:
<p>Paragraph in <u>parag</u>r|aph|.</p>
That's right, the selected text is aph, and the text node is raph., Because before the raph the new text node appears inside the u node.
Now when calling $(startContainer).prevAll().each(function(index, node) ... I expected this to return U (which contains the text node with parag) and another text node (which contains Paragraph in).
However, it only returns U, not the text node to the left of it.
Why is this? How to get all nodes with one level up to my startContainer, including text nodes with jQuery?
source share