I'm trying to figure out how I will target a line where the caret is currently in, and then do some basic replace in that line.
Here's the sample I have:
function process() {
//Onclick of this button, remove "aaa" and "bbb" wherever it appears only where the caret is currently in
let textarea = document.getElementById("textarea1");
textarea.value = textarea.value
.replaceAll('aaa', "")
.replaceAll('bbb', "")
}
<textarea id='textarea1'>
aaaline1bbb
aaaline2bbb
line3
</textarea>
<button onclick='process();'>Process</button>
Here, whenever a user places their caret in line 1 or line 2, it will delete both "aaa" and "bbb" in the whole line. This is just a sample for what I really want to do.
The main problem I have is how to target a line where the caret is.
Thank you in advance for any help!