.length JQ Home  <<  Core & Internals  <<  .length

Elements count.

Description

The .length property holds the number of elements in the jQuery object.

Syntax

Signature Description
.lengthThe number of elements in the jQuery object.

Parameters

None.

Return

A Number object.

.length Example Core  <<  Top

The number of elements in the jQuery object.


$(function(){
  $('#btn2').on('click', function() { 
    var noOfElements = $('p').length; 
    alert('There are ' + noOfElements + ' p nodes in the DOM'); 
  });
}); 

Press the button below to action the above code:

Related Tutorials

jQuery Basic Tutorials - Lesson 2 - jQuery Core & Internals