Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

jquery
communitycreator

What is the size() method in jQuery?

Shubham Singh Kshatriya

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The size() method in jQuery is used to find the number of elements that match the given jQuery selector.

Syntax

$(selector).size();

Parameters

This method doesn’t accept parameters.

Return value

This method returns the number of elements that match the given jQuery selector.

Example

Let’s look at an example of the size() method in the code snippet below:

Console

Explanation

In the HTML tab:

  • Lines 5 to 9: We create a 5 HTML div.
  • Line 7: We import the jQuery script.

Note: We import the older version.

In the JavaScript tab:

  • Line 3: We use the size() method to count the number of div.
  • Line 5: We output the numberOfDivs on the console.

Output

The size() method counts the number of elements that match the selector div and output the result to the console.

Note: This method was deprecated in the jQuery version ^1.8 and was removed in the jQuery version ^3.0.

RELATED TAGS

jquery
communitycreator

CONTRIBUTOR

Shubham Singh Kshatriya

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring