开发者

Conditional if/then for gt: in jQuery

How do you say :

if there are more than 2 .quick_fact then

My attempt:

if $开发者_JAVA百科(".quick_fact:gt(2)") { }

Which evidently is always true.


A jQuery object has a length property representing the number of matched elements. So simply do a typical "greater than" comparison.

if( $('.quick_fact').length > 2 ) {
    // There were more than two
}


if ($(".quick_fact").size() > 2 ) { }

Or:

if ($(".quick_fact").length > 2 ) { }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜