Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

80
Views
input event with if condition

I use eventlistener to detect the rows in textarea, but when I press backspace the if condition doesn't work. How can I improve this?

$('textarea').on('input', function() {
  // Get the scroll height of the textarea
  let taHeight = $('textarea').scrollHeight;
  let numberOfLines = Math.floor(taHeight / 16);
  height(numberOfLines);

})

function height(numberOfLines) {
  console.log(numberOfLines);
  if (numberOfLines == 2) {
    $('textarea').removeClass('row-2 row-3').addClass('row-2');
  } else if (numberOfLines == 3) {
    $('textarea').removeClass('row-2 row-3').addClass('row-3');
  } else {
    $('textarea').removeClass('row-2 row-3');
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea></textarea>

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!