How many elements were selected by jQuery

Recently I needed to find out how many elements were selected by jQuery. jQuery selector returns an array of elements jQuery object that has .length attribute. So the easiest way is to get the length of returned jQuery object. The size of that object will be equal to the number of selected elements. $('.someClass').length;

// Assume you have 4 .class elements
$('.class').length;
// would return

Comments