Reputation: 431
I made a fiddle to explain my problem.
As you can see when you type into the textbox
and press the button
the textbox
value is replaced with ""
but what would I need to do in order to replace the text AND remove the line break?
I'm sure it's something simple that I am overlooking... Thanks.
$('button').click(function(e) {
var info = $('#textField').val();
var textarea = document.getElementById("todoListSave");
textarea.value = textarea.value.replace(info, "");
});
<button>Click Me</button>
<input type="text" placeholder="Text to remove from textarea..." id="textField">
<textarea id="todoListSave">
1
2
3
4
5
6
7
</textarea>
Upvotes: 1
Views: 560
Reputation: 2585
You just need to replace the line break as well, e.g. with
var re = new RegExp(info + '\n', 'g');
Updated fiddle http://jsfiddle.net/wdo4Lw57/3/
Upvotes: 2
Reputation: 1117
http://jsfiddle.net/wdo4Lw57/1/
textarea.value = textarea.value.replace(info + "\n", "");
This should fix your issue.
You need to add the new line character to the end.
Upvotes: 1