Paragraphs in javascript

前端 未结 3 1488
南笙
南笙 2021-01-24 03:50

Do you know if there is an easy way of counting paragraphs in a textarea using nothing but javascript?

Thanks,

3条回答
  •  故里飘歌
    2021-01-24 04:25

    Try this one:

    document.getElementById('textarea_id').value.replace(/\n$/gm, '').split(/\n/).length;
    

    This will ignore empty strings (see @Sean Vieira answer)

提交回复
热议问题