"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Friday, June 15, 2012

get count of number of elements were selected by jQuery

jQuery selector returns a jQuery object that has .lenght property. So the easiest way to get the length is using the .lenght property.

var iCount = $('.cssClass').length;

If you want to know how many div elements present on the page then,

var eCount = $('div').length;



jQuery also provides .size() method, which also does the same thing as the .lenght property. But the .lenght property is preferred because it does not have the overhead of a function call.

If u had any trouble just ask, Happy to help u :)
Stay Tune...
Have a nice day... 'N happy Coding :)

No comments: