0

Is there any way to select first two lines from text in a div.

Content in div:

/*------------------------
| some content goes here |
| inside div or any      |
| container in HTML. is  |
| it possible to select  |
| first two lines        |
| displaying in browser  |
----------------------- */

SelectedText = "some content goes here inside div or any"
Tarun
  • 1,888
  • 3
  • 18
  • 30

2 Answers2

0
var first_line = $("#divElement").text().split("\n")[1];
var second_line = $("#divElement").text().split("\n")[2];

JSFiddle Example

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
0

Hello you can check below code

 <script type="text/javascript">
function runTest(){
var str=document.getElementById("id1").value;
var arr = str.split(/[\n\r]/g);
alert(arr[0]+arr[1]);
}
</script>
<textarea id="id1">
some content goes here
inside div or any
container in HTML. is 
it possible to select
first two lines 
displaying in browser
</textarea>

<a href="#" onClick="runTest();">myLink</a>
Vishal
  • 875
  • 1
  • 7
  • 15