Skip to content

Counting Characters Inside a Paragraph

How do you count how many characters are in a paragraph tag with jQuery/Javascript? For example in this sample it would be 3.

<div>
 <p class="tag">Jam</p>
</div>

Are you able to select the characters with .length() somehow?

Answer

This is what you want

$.trim($("p").text()).length;