0

I have a textarea in which text pieces (stored on each data-code attribute) are appended when clicking on an specific DIV:

$(document).on('click', '.extrasPanel .contentVars div', function(e){
        varCode = $('.active').attr('data-code');
        varText=$(document).find('textarea').val();
        $(document).find('textarea').val(varText+varCode);
        checkCounter(e);
});

Once a .contenVars div is clicked, its data-code value is added to whatever is typed on textarea, and to keep typing the user must click again on the textarea.

I would like the user to keep typing after importing this pieces of text widthout needing to click back on it, so that the cursor remains on the last position, after the last imported character (as if you would have pasted it).

I have tried adding e.preventDefault; at the end of the function, with no possitive result.

Biomehanika
  • 1,530
  • 1
  • 17
  • 45

2 Answers2

1

If you're using jQuery, you can try .focus()

jQuery('textarea').focus();
Daft
  • 10,277
  • 15
  • 63
  • 105
0

May this link will helps you..

jquery-caret.js

This is a very simple lightweight plugin to allow you to move the caret (or cursor) position in an or element

$('textarea').caretToEnd();
iTechOwl
  • 150
  • 11