1

i want to insert text in textarea on a button click and this text should be added at the place of my cursor not the end of the text

function add1(){
  var msg=$('#msg').val();
  $('#msg').val(msg+"hello");
}
function add2(){
  var msg=$('#msg').val();
  $('#msg').val(msg+"world");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="msg"></textarea>
<button onclick="add1()">hi</button>
<button onclick="add2()">world</button>
vivek modi
  • 800
  • 2
  • 7
  • 23

0 Answers0