The King is The King is - 4 months ago 5x
jQuery Question

How to add a break-line in a textarea by clicking a link

I have search and all I could get is just changing the value of the textarea.

What I really want is when I click a link, it adds a new line-break to my textarea

<a href="javascript:;"add new line break</a>
//run code to add new break line


You can try something like this to add a line break at the end of the textarea :

f.e :



Something like this should do the trick :

$("#btn").click(function() {
    var index = $('#text').prop("selectionStart");
    var text= $('#text').val();
    var r=text.slice(0, index) + "\n" + text.slice(index);