jQuery length property

The length property in jQuery is used to count the number of elements in the jQuery object.

The size() function also returns the number of elements in the jQuery object. But it is preferred to use the length property over the size() function because the length property avoids an extra function call, so it is quicker than the size() function. We can use the length property as an alternative of the size() function because the size() function is deprecated in jQuery version 1.8, and it is completely removed in version 3.0.

Syntax

This property returns the length of the specified selector. The selector is the jQuery object whose length is to be calculated.

Example

In this example, there are three paragraph elements. We are using the length property to count the number of paragraph elements.

Test it Now

Output

After the execution of the above code, the output will be -

jQuery length property

After clicking the button, the output will be -

jQuery length property




Latest Courses