views:

15

answers:

2

Hi all, my problem is very simple: I want to know how many characters are inside a 'p' tag and if the number is over 100 fire an event on hover. I tried to retrieve the char number like this:

var charLength = $('.myPar').val().length;
<p class="myPar">this is the content of the paragraph</p>

it returns always zero as value and it seems to work only for textarea or input tags. Any idea?

Thanks in advance!

Mauro

+3  A: 

$('.myPar:first').html().length or $('.myPar:first').text().length depending on your use case

balupton
A: 

replace .val() with .text()

var charLength = $('.myPar').text().length;
Christian Smorra