1479 posts The right tools with none of the gimmicks
  • Affiliate Level 4
  • Author Level 7
  • Beta Tester
  • Collector Level 2
+7 more
PixelBin
says

Is there a jQuery function that counts how many elements are in a certain element? For example, I want to count how many <li /> tags are in a certain <ul /> list.

Thanks fellas.

1479 posts The right tools with none of the gimmicks
  • Affiliate Level 4
  • Author Level 7
  • Beta Tester
  • Collector Level 2
+7 more
PixelBin
says

Ahhh, nevermind. I think I got it. Sorry for the useless thread. :(

382 posts
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 5
  • Collector Level 2
+3 more
blabus
says

I believe this would work:

$(”#UL-ID”).length();

and you’d of course replace ‘UL-ID’ with the ID of your unordered list.

1479 posts The right tools with none of the gimmicks
  • Affiliate Level 4
  • Author Level 7
  • Beta Tester
  • Collector Level 2
+7 more
PixelBin
says

Hmmm… I’m using $(‘name of ul here’).find(‘li’).size() which works and shows the right number but there’s a Javascript error in the process.

Edit: Yeah .length() completely breaks all the scripts. .size() at least showed the right number until I pressed something.

94 posts
  • 7 Years of Membership
  • Affiliate Level 2
  • Author Level 4
  • Collector Level 1
+6 more
JimmyP
says

You can use ”.length” or ”.size()” ... not ”.length()”

426 posts
  • 6 Years of Membership
  • Affiliate Level 2
  • Author Level 4
  • Beta Tester
+4 more
vasilios
says

Just out of shear curiosity, has anyone done any speed tests between ”.length” and ”.size()”?

by
by
by
by
by
by