Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js window selection get new line

var userSelection
function countLineBreaks(){

  //Textarea
  var textarea = document.getElementById("textArea");  

  //Get user selection
  userSelection = (textarea.value).substring(textarea.selectionStart,textarea.selectionEnd);
  
  //Simple regex to check for line break
  var matches = userSelection.match(/
/g);

  //Count line breaks
  var lineBreaksCount = matches ? matches.length : 0
   
  console.log(lineBreaksCount + ' Line breaks')
}
   
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #window #selection #line
ADD COMMENT
Topic
Name
2+1 =