Search code examples
javascriptcountparagraphs

Paragraphs in javascript


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

Thanks,


Solution

  • Try this one:

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

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