How do I get the number of rows in the textarea input box?

is exactly how to get the number of lines of existing text in textarea.

Mar.21,2021

Don't say much else, just go to the code

<!DOCTYPE html>
<html>
<head>
  <title>Title</title>
  <script>
    window.onload = function () {
      function onGetLines() {
        var tmp = document.querySelector('-sharptest').value;
        var lines = tmp.split(/\r*\n/);

        var linesCount = lines.length - (navigator.userAgent.indexOf('MSIE') !== -1);
        console.log('', linesCount);
      }

      document.querySelector('-sharpgetLines').addEventListener('click', onGetLines, false)
    }
  </script>
</head>
<body>
<textarea name="test" id="test" cols="30" rows="10"></textarea>
<button id="getLines"></button>
</body>
</html>
Menu