MrFox
MrFox

Reputation: 3253

Get selected text from HTML by javascript?

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". (The text has to be read only and is formated.)

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

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

How do I get the selected text without loosing the selection?


Solution:

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

Upvotes: 1

Views: 838

Answers (1)

cletus
cletus

Reputation: 625007

Here is how to get text selection with Javascript.

Upvotes: 1

Related Questions