0

Basically this question is pretty similar to:

Insert value into TEXTAREA where cursor was

JSFiddle: http://jsfiddle.net/rQXrJ/1/

The thing is, I can't get it to work for multiple textareas.

I've tried multiple combinations of things but still no success:

1)

$("#foo-1").click(function () {
    $textBox = $(this);    
    $textBox.focusout(saveSelection);
});

$("#foo-2").click(function () {
    $textBox = $(this);    
    $textBox.focusout(saveSelection);
}); 

2)

function changeTextBox(newID) {
    var fullID = "#" + newID;
    $textBox = $(newID);      
    $textBox.focusout(saveSelection);
}
$(".txt").click(function () {
    var id = $(this).attr("id");
    changeTextBox(id);         

});   

Here's my jsFiddle: https://jsfiddle.net/yneco5ft/

Community
  • 1
  • 1

1 Answers1

1

You need to give the same class to your textareas and set $textBox to that class.
Example : http://jsfiddle.net/rQXrJ/283/

Matin Kajabadi
  • 3,414
  • 1
  • 17
  • 21