How to get the current active text within a scrolled DIV
css, dom, html, javascript, jquery
Solution
Here's a little demo that should do what you're expecting: little link (works with variable sizes as well). The idea is to automatically create a separate `span` for each word, and then, each time the `div` is scrolled, check which `span`s are visible (by checking their `top` offset), thus updating document selection range. If anything isn't clear I'd be glad to explain it.
Problem
A chipped `DIV` containing paragraphs that need a scrollbar e.g. ``` <div id="text" style='overflow:scroll;width:200px;height:200px'> <div style='font-size:64px;'>BIG TEXT</div> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div> ``` When the scrollbar move, the text change (due to `overflow:scroll`), is it possible to select only the text displayed in the current view port? Example: http://jsfiddle.net/cxgkY/15/ Updated: The inner HTML might contains variable sized text