views:

126

answers:

2
A: 

Here is a post on working with selected text. The getSelection() method can be used to get the selected text, then you should be able to replace that text with text wrapped in a tag.

Dave Swersky
There's no link Dave :)
Mike Houston
Woops! Added... 8-)
Dave Swersky
A: 

Highlighting the selected text doesn't necessarily require you to wrap it. In fact, trying to wrap it is difficult if the range of the selection spans multiple tags (i.e. doesn't surround nicely closed tags).

Here's an answer that highlights the current selection without wrapping it: http://stackoverflow.com/questions/1622629/javascript-highlight-selected-range-button/1623974#1623974.

He uses execCommand to let the browser highlight the current document selection for you. Pretty sweet.

Crescent Fresh
awesome thanks... I figured there was someone else out there who had already asked this question. As a result I've voted to close this question and have it point to the one you mentioned.
vrish88