【发布时间】:2015-09-11 03:53:24
【问题描述】:
假设我有这个 HTML
<div id="someparent">
Foo
<span id="one">Selection starts anywhere inside here</span>
<span id="two">Selection ends anywhere inside here</span>
<span id="three">Some more text here</span>
Bar
</div>
我想返回跨度#one 和跨度#two 节点(这样我就可以在它们周围再包裹一个跨度*)。如果 foo 和 bar 是选择的起点和终点,则会返回 div #someparent(两次)。
*即使使用 jQuery,如何做到这一点也会很有帮助。
这类似于this question which asks for the single parent of the whole selected text。
【问题讨论】:
标签: javascript jquery