There is no way in Javascript to do this, the smallest thing you can interact with is, in general, a DOM element. So you can technically wrap every word inside <span>, but that seems to have seriously gone too far and probably also had a big impact on performance.
Instead, what most sites that provide this functionality do, they make a popup pop-up whenever you select text ( see this question for some code to get the current selection ).
Personally, I find this really annoying (e.g. nytimes.com does this, for example), but it is possible that only I ...
source
share