BernardA
BernardA

Reputation: 1523

jquery count characters on span tag

I may be missing something pretty obvious, but somehow I am struggling to count the characters inside a span tag. The span is dynamically populated and I am trying to get its lenght, spaces included, to adjust the width of a column. If I run only text() or html() I can get the content:

<span id="vlen00">someword</span>

vlenght = $('#vlen00').text();//vlenght is assigned 'someword'
vlenght = $('#vlen00').html();//this also gives me 'someword'

But when I tried to size it up like:

vlenght = $('#vlen00').text().lenght;//that gives me 'undefined'
vlenght = vlenght.lenght;//that also gives me 'undefined'

Thanks!

Upvotes: 0

Views: 2554

Answers (2)

codebox
codebox

Reputation: 20254

You have the name of the property wrong - it's length not lenght

Upvotes: 0

PSR
PSR

Reputation: 40318

change lenght to length.It will work

change

vlenght = $('#vlen00').text().lenght; to

vlenght = $('#vlen00').text().length;

Upvotes: 2

Related Questions