2

Like SO has for example the B button:

**strong text**

But strong text to be automatically selected, and the cursor to be positioned just before the s

Alex
  • 66,732
  • 177
  • 439
  • 641

1 Answers1

2

You could use my Rangy Inputs jQuery plug-in now that I've finally got round to documenting it. Using it, the following will do the job:

$textArea = $("#yourtextarea");
$textArea.focus();
$textArea.surroundSelectedText("**", "**");

This will select the same text as was selected before, which is what SO does. However, if you prefer to have a caret before the "s" as you say then you can add the following:

$textArea.collapseSelection(true);

jsFiddle example: http://jsfiddle.net/AL7uY/

Tim Down
  • 318,141
  • 75
  • 454
  • 536