Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As @standardModel says, Rangy gives you full* DOM Range support in IE and has a helpful <a href="http://code.google.com/p/rangy/wiki/RangyRange#getNodes%28%5BArray_nodeTypes%5B,_Function_filter%5D%5D%29" rel="nofollow"><code>getNodes()</code></a> method that you could use:</p> <pre><code>var sel = rangy.getSelection(); if (sel.rangeCount) { var range = sel.getRangeAt(0); var spans = range.getNodes([1], function(node) { return node.nodeName.toLowerCase() == "span" &amp;&amp; range.containsNode(node); }); // Do stuff with spans here } </code></pre> <p>If you'd rather not use something as bulky as Rangy, the following function will tell you if an element is completely selected:</p> <pre><code>function isSelected(el) { if (window.getSelection) { var sel = window.getSelection(); var elRange = document.createRange(); elRange.selectNodeContents(el); for (var i = 0, range; i &lt; sel.rangeCount; ++i) { range = sel.getRangeAt(i); if (range.compareBoundaryPoints(range.START_TO_START, elRange) &lt;= 0 &amp;&amp; range.compareBoundaryPoints(range.END_TO_END, elRange) &gt;= 0) { return true; } } } else if (document.selection &amp;&amp; document.selection.type == "Text") { var textRange = document.selection.createRange(); var elTextRange = textRange.duplicate(); elTextRange.moveToElementText(el); return textRange.inRange(elTextRange); } return false; } </code></pre> <p>jsFiddle example: <a href="http://jsfiddle.net/54eGr/1/" rel="nofollow">http://jsfiddle.net/54eGr/1/</a></p> <p>(*) Apart from handling Range updates under DOM mutation</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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