I want append inside a TextArea some html code (just the syntax, like a string). I don't know the reason but my code doesn't work well, in fact If I run the code and I press the button than the html code will append into the textarea correctly but if I write something inside the textarea and after I try to click or re-click the button to append the html code nothing happen! Here my test fiddle:
https://jsfiddle.net/jkLh0wat/1/
I also use Django, in my case textarea was given by django form (in the form I use an id "desc" to the textarea field) but I think isn't a Django problem since it is a html-jquery problem....
this is the code:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<button type="button" class="btn btn-info btn-xs" id="link">link</button>
<textarea id="desc" style="width:350px;height:200px;border:1px solid"><b>hello</b></textarea>
<script>
$("#link").on('click', function() {
$(document.createTextNode("<a href='link'>titolo-link</a>")).appendTo($("#desc"));
})
</script>