tags:

views:

20

answers:

3

I know that usually you want to strip these out, but I need the true char count and I can't find out how to get it...

Thanks for the help

+1  A: 

What's wrong with .length? That counts line breaks as characters (I assume you meant a line break by 'ENTER'?)

chigley
I'm calling .text().length and it's stripping them out. According to what I've read, .text() removes all formatting chars.
Keith Myers
@Keith - don't use `$.text()` then! From the manual: "Due to variations in the HTML parsers in different browsers, the text returned may vary in newlines and other white space." Because of this it wouldn't be a reliable option anyway!
chigley
Telling me it doesn't work isn't very useful... I knew that already. I was hoping for an alternative that DOES work.
Keith Myers
@Keith - how about you post some code then? Not all of it, just the relevant snippet. What are you trying to count the characters of? Document? Input? Paragraph?
chigley
A: 

This plugin seems to do the job.

It counts words too.

Marko
A: 

Use the length property on any string to get its character count. E.g.

'this is an example string'.length // == 26

or, for jQuery:

$('#my_textarea').html().length

N.B. use html() not text() to avoid having jQuery do things like removing line-breaks.

lonesomeday