Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>window.getSelection()</code> gives you a <a href="http://www.w3.org/TR/html5/editing.html#selection-0" rel="nofollow noreferrer">Selection</a> object. Use <code>selection.rangeCount</code> and <code>selection.getRangeAt()</code> to get a <a href="http://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html" rel="nofollow noreferrer">Range</a> object representing which selection you want.</p> <p>Now you can get the first and last nodes in the selection from <code>range.startContainer</code>/<code>startOffset</code> and <code>range.endContainer</code>/<code>endOffset</code>. You could then walk up and down the tree to pick up all the elements in between those two positions, eg. using the <code>getElementsBetweenTree()</code> function from <a href="https://stackoverflow.com/questions/2514125/jquery-select-elements-between-two-elements-that-are-not-siblings/2515169#2515169">this answer</a>.</p> <p>Unfortunately, IE's <a href="http://msdn.microsoft.com/en-us/library/ms535872%28v=VS.85%29.aspx" rel="nofollow noreferrer">TextRange</a> model is totally different to the W3 and HTML5 standard, and in general much worse. It does't give up the start and end positions nearly as easily, and not in any reliable way. All you get is <code>parentElement</code> to tell you the common ancestor, and from there you're limited to guessing where the range is based on creating a new Range and calling <code>moveToElementText</code> on it then <code>compareEndPoints</code> with the selection range. And if you need to know the exact text selection you're then guessing based on <code>moveStart</code>/<code>moveEnd</code>​ing the range and comparing, which isn't fun at all.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload