jquery how to retrieve the number of characters in a p tag?
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 t开发者_如何学JAVAo work only for textarea or input tags. Any idea?
Thanks in advance!
Mauro
$('.myPar:first').html().length
or
$('.myPar:first').text().length
depending on your use case
replace .val() with .text()
var charLength = $('.myPar').text().length;
精彩评论