have you tried:
$("#yourAnchor").click(function () {
$("#yourTextarea").val("your text");
});
not sure about autohighlighting, though.
EDIT:
To append:
$("#yourAnchor").click(function () {
$("#yourTextarea").append("your text to append");
});
What you ask for should be reasonably straightforward in jQuery-
$(function() {
$('#myAnchorId').click(function() {
var areaValue = $('#area').val();
$('#area').val(areaValue + 'Whatever you want to enter');
});
});
The best way that I can think of highlighting inserted text is by wrapping it in a span with a CSS class with background-color set to the color of your choice. On the next insert, you could remove the class from any existing spans (or strip the spans out).
However, There are plenty of free WYSIWYG HTML/Rich Text editors available on the market, I'm sure one will fit your needs
Here is a quick solution that works in jQuery 1.9+:
a) Get caret position:
function getCaret(el) {
if (el.prop("selectionStart")) {
return el.prop("selectionStart");
} else if (document.selection) {
el.focus();
var r = document.selection.createRange();
if (r == null) {
return 0;
}
var re = el.createTextRange(),
rc = re.duplicate();
re.moveToBookmark(r.getBookmark());
rc.setEndPoint('EndToStart', re);
return rc.text.length;
}
return 0;
};
b) Append text at caret position:
function appendAtCaret($target, caret, $value) {
var value = $target.val();
if (caret != value.length) {
var startPos = $target.prop("selectionStart");
var scrollTop = $target.scrollTop;
$target.val(value.substring(0, caret) + ' ' + $value + ' ' + value.substring(caret, value.length));
$target.prop("selectionStart", startPos + $value.length);
$target.prop("selectionEnd", startPos + $value.length);
$target.scrollTop = scrollTop;
} else if (caret == 0)
{
$target.val($value + ' ' + value);
} else {
$target.val(value + ' ' + $value);
}
};
c) Example
$('textarea').each(function() {
var $this = $(this);
$this.click(function() {
//get caret position
var caret = getCaret($this);
//append some text
appendAtCaret($this, caret, 'Some text');
});
});
If you want to append content to the textarea without replacing them, You can try the below
$('textarea').append('Whatever need to be added');
According to your scenario it would be
$('a').click(function()
{
$('textarea').append($('#area').val());
})
I used that and it work fine :)
$("#textarea").html("Put here your content");
Remi