Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can some one guide me how to highlight first line of the text area.

Thanks.
Posted

1 solution

This is done by a call to setSelectionRange:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange[^].

Solution 1 won't work due to some bugs, but some ideas are correct: first, you need to find out the end of the first line, either by splitting, or, simpler, by the search for nearest end-of-line position: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search[^].
Then call
JavaScript
myTextArea.setSelectionRange(0, endOfFirstLine);


—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900