title: Insert text at the cursor position to a CKEditor using jQuery
body: <p>I'm trying to add a piece of text to an existing CKEditor using jQuery.
  This needs to be done when a link is clicked.</p>
  
  <p>I tried this solution, which works for regular textareas, but not for CKEditor:</p>
  
  <pre><code>jQuery.fn.extend({
    insertAtCaret: function(myValue) {
      return this.each(function(i) {
        if (document.selection) {
          //For browsers like Internet Explorer
          this.focus();
          sel = document.selection.createRange();
          sel.text = myValue;
          this.focus();
        } else if (this.selectionStart || this.selectionStart == '0') {
          //For browsers like Firefox and Webkit based
          var startPos = this.selectionStart;
          var endPos = this.selectionEnd;
          var scrollTop = this.scrollTop;
          this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length);
          this.focus();
          this.selectionStart = startPos + myValue.length;
          this.selectionEnd = startPos + myValue.length;
          this.scrollTop = scrollTop;
        } else {
          this.value += myValue;
          this.focus();
        }
      })
    }
  });
  </code></pre>
  
  <p>There is also an option to use: <code>$('#editor').val()</code>, but this appends the text at the end or the beginning and not at the cursor.</p>
  
  <p>So, is there a way to accomplish this?</p>