I am using Ckeditor
View:
@Html.TextArea("editor", new { @class = "ckeditor", id = "aboutme" })
Javascript:
$(function () {
$('input#insertPattern').click(function () {
var txtarea = document.getElementById("aboutme");
var selection = txtarea.getSelection().getStartElement().getOuterHtml();
alert(selection);
}});
If i click to buton , i can not alert selection number of mouse click in Html.TextArea in Ckeditor.
Error:
In this part of javascript code
var selection = txtarea.getSelection().getStartElement().getOuterHtml();
I get below error,
uncaught typeerror undefined is not a function
Where i miss ? How can i get selection of mouse click ?
解决方案
Ultimately you want to insert text where exactly the mouse points right. This piece of code do that.
CKEDITOR.instances['aboutme'].insertText("insert some text into this string");