JavaScript Selection and Range
basics
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.