insertCaret using javascript
<p>I found some code using google search:</p>

<pre><code>function insertAtCaret (textarea, icon) { 
    if (document.getElementById(textarea).createTextRange &amp;&amp; document.getElementById(textarea).caretPos) { 
            var caretPos = document.getElementById(textarea).caretPos; 
            selectedtext = caretPos.text; 
            caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == '' ? icon + '' : icon;//this line I am not understand
}
}

function storeCaret (textarea) { 
    if (document.getElementById(textarea).createTextRange) document.getElementById(textarea).caretPos = document.selection.createRange().duplicate(); 
}
</code></pre>

<p>here why need judge </p>

<p>caretPos.text.charAt(caretPos.text.length - 1) == ''</p>

<p>I think icon+'' and icon are equal</p>
