I am trying to highlight single line of text in <textarea>
, similar the way we select the text by cursor. But instead of mouse I want this happen automatically. I setted the line of text is separated by '\n'. I want to highlight it in yellow. I wanted to highline the corresponding line of text by click on the button. I hope I can select the line of text, not the fixed range of character. Thank you very much.
Here is my code:
$(document).ready(function(){
var text = 'line 1\nline 2\nline 3\n';
$('#text').val(text);
});
#container {
float: left;
}
button {
width: 50px;height: 30px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="container">
<button id="line1">line 1</button><br><button id="line2">line 2</button><br><button id="line3">line 3</button>
</div>
<textarea id="text" rows="6"></textarea>