jQuery如何检索ap标签中的字符数?

Mau*_*o74 2 jquery character

我的问题很简单:我想知道'p'标记内有多少个字符,如果数量超过100,则会在悬停时触发一个事件。我试图像这样检索字符数:

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

它始终返回零作为值,并且似乎仅适用于文本区域或输入标签。任何的想法?

提前致谢!

毛罗

bal*_*ton 5

$('.myPar:first').html().length$('.myPar:first').text().length 取决于您的用例