views:

18

answers:

2

How do you say :

if there are more than 2 .quick_fact then

My attempt:

if $(".quick_fact:gt(2)") { }

Which evidently is always true.

+3  A: 

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
}
patrick dw
Answer avalanche... you got me.
Peter Ajtai
You guys just rocked my jQuorld.
Trip
@Trip - Glad I could help. :o)
patrick dw
+2  A: 
if ($(".quick_fact").size() > 2 ) { }

Or:

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