Answers for "js window selection get new line"

0

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(/\n/g);

  //Count line breaks
  var lineBreaksCount = matches ? matches.length : 0
   
  console.log(lineBreaksCount + ' Line breaks')
}
Posted by: Guest on August-07-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language