jQuery count characters and add class

后端 未结 4 1615
予麋鹿
予麋鹿 2021-01-07 04:02

Is it possible to use jQuery to count how many characters are in, for example, an

  • , and if the amount is greater than XX characters, apply a class to
  • 4条回答
    •  被撕碎了的回忆
      2021-01-07 04:26

      Why not select your

    • element into a variable and get its length?

      var length = $('li').html().length;
      

      From here, just check if the value on length is greater than the value you're comparing to and use .addClass()

    提交回复
    热议问题