title: How to insert text at selected position inside <p> tag
body: <p>I need a function to insert text at cursor position inside the <code>&lt;p&gt;</code> tag and get back focus on the same</p>
  
  <p>I have the following code for <code>textarea</code>, but it is not working for <code>&lt;p&gt;</code> tag : </p>
  
  <pre><code>var front = (txtarea.value).substring(0, caretPos);
  var back = (txtarea.value).substring(txtarea.selectionEnd,txtarea.value.length);
  txtarea.value = front + text + back;
  caretPos = caretPos + text.length;
  txtarea.selectionStart = caretPos;
  txtarea.selectionEnd = caretPos;
  txtarea.focus();
  txtarea.scrollTop = scrollPos;
  </code></pre>