When you use the click on stack overflow's button to add code snippets in the rich text editor it adds some text like this 'enter code here'. It also selects (or highlights) this inserted text with the caret so the user can easily replace the text by just typing. I want to implement the same functionality to my rich text editor.
I created a javascript function that enters a dummy text inside pre and code tags. Now I want to use a functionality similar to this javascript function: http://www.w3schools.com/jsref/met_textarea_select.asp
The problem is that this function selects the whole textarea and I only want to select my dummy text inside pre and code tags.
I insert the dummy text in the following way:
var preElement = new CKEDITOR.dom.element("pre");
var codeElement = new CKEDITOR.dom.element("code");
preElement.append(codeElement);
codeElement.setText('insert your code here');
editor.insertElement(preElement);
Oh, and I am using CKEditor for this and a plugin I wrote to execute this function.