jQuery - check text length with .length

0 votes
332 views
added Jul 12, 2019 in jQuery by LC Marshal Captain (25,790 points)
recategorized Mar 26, 2021 by LC Marshal
$('.price.at-summary').each(function(){
  var text = $(this).text();
  if ( text.length > 31 ) {
    $('.calculator.at-summary').addClass('x-m-price').fadeIn(400);
  }
  else if ( text.length < 30 ) {
    $('.calculator.at-summary').addClass('r-m-price').fadeIn(400);
  } 
  else {
    $('.calculator.at-summary').fadeIn(400);
  }
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...