Code Snippets

Count elements in jQuery

2010/05/02 | Comment?

The method you can use to count the element’s of a jQuery selection is “size()”


$("div.class").size();

So you are able to do


if ($("div.class").size() > 0)
  // Do something
else
  // Another thing

or whatever you want to do ;)

Share and Enjoy:
  • Tumblr
  • Twitter
  • FriendFeed
  • Digg
  • StumbleUpon
  • del.icio.us
  • Technorati
  • Sphinn
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • RSS
Tags: , , , ,

have your say

:

:


«
»