Skip to content
Advertisement

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?

Advertisement

Answer

This is what you want

$.trim($("p").text()).length;
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement