开发者

jQuery find if a dynamic generated <p> have text

I try to find if a dynamic created <p> have text. '.layer'+count returns my

class but I can not get it to work with .lenght.

if ( ($('.layer'+count).text()).length > 0 ){
alert ('I have text')
}

Any tips on making this开发者_StackOverflow社区 work? Thanx


if ( ($('.layer'+count).text().length ) > 0 )
{
    alert ('I have text')
}

In your code the paranthesis order was not the right one. It should be

($('.layer'+count).text().length)

and not

($('.layer'+count).text()).length

Actually there is no need of the extra (. You can simply write

if ( $('.layer'+count).text().length > 0 )
{
    alert ('I have text')
}


The extra parenthesis aren't needed around $('.layer'+count).text() but it should work nevertheless. Are you absolutely sure you selector matches the element? You can test that by using alert($('.layer'+count).length), that would alert the amount of elements matched.


What happens when you do:

alert($('.layer'+count).text())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜