<textarea name="descricao" class="form" rows="9"></textarea>
<a href="#" data-message="Bom dia, como voce esta?">Saudação</a>
<a href="#" data-message="texto do exemplo numero 2">Exemplo 2</a>
<a href="#" data-message="texto do exemplo numero 3">Exemplo 3</a>
<a href="#" data-message="texto do exemplo numero 4">Exemplo 4</a>
JavaScript
function setarValor() {
var menssagem = $(this).data('message'); //Pego a menssagem do campo data
var textAreaPosition = $('textarea').prop("selectionStart"); //pego a posição no text area
var textAreaValue = $('textarea').val(); // pego valor do text area
var valorConcatenado = [textAreaValue.slice(0, textAreaPosition), menssagem, textAreaValue.slice(textAreaPosition)].join(''); // faço a concatenação da menssagem na posição
$('textarea').val(valorConcatenado); //seto valor no textarea
}
//Ele execulta após toda a pagina ser renderizada
$(document).ready(function () {
//seto de click nos seus links
$('a').click(setarValor);
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.