JavaScript Selection and Range

Author: yifei / Created: June 8, 2017, 5:40 p.m. / Modified: June 8, 2017, 10:35 p.m. / Edit


window.getSelection and document.getSelection all returns the Selection object, the selection object is almost useless.

window.getSelection.getRangeAt(0) returns a Range object. for history reasons, there is only one range in each selection.

rangeAncestor = range.commonAncestorContainer; commonAncestorContainer is the common ancestor of the range elements.

有任何问题可以发邮件到 kongyifei (at) 讨论