Count characters in paragraph using jQuery (*not* for input/textarea)

前端 未结 4 1809
花落未央
花落未央 2021-01-18 00:55

How do I work out in jQuery a character counter of a p/div tag?

Basically i want to show a different css value IF the character value >=50.

Been struggling f

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-18 01:35

    var $div = $('#mydiv');
    if($div.text().length >= 50) {
        $div.addClass('class');
    }
    

提交回复
热议问题