Get selected text from HTML by javascript?
<p>I have a page with formated text and a toolbar (images with click events) beside it.
One of the tool-commands is meant to be "mark yellow". <em>(The text has to be read only and is formated.)</em></p>

<p>I tried to use <code>document.getSelection()</code> and <code>window.getSelection()</code>, but they seem to be designed for input fields only.</p>

<p>The other problem is, that as I click the tool bar my selection gets lost.</p>

<p>How do I get the selected text without loosing the selection?</p>

<p><br/></p>

<h2>Solution:</h2>

<p>The clue was to use <code>onmousedown=""</code> 
or jQuery: <code>.mousedown()</code> function to avoid loosing the selection.</p>
