开发者

Conditional if/then for gt: in jQuery

开发者 https://www.devze.com 2023-01-12 06:59 出处:网络
How do you say : if there are more than 2 .quick_fact then My attempt: if $开发者_JAVA百科(\".quick_fact:gt(2)\") { }

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

精彩评论

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