- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between jQuery.size() and jQuery.length?
jQuery.size() method
This method returns the number of elements in the object. The size() method deprecated in jQuery 1.8 and completely removed in jQuery 3.0. As an alternative, the length property is used.
Example
You can try to run the following code to learn how to work with size() method.
Note: To run the jQuery size() method, use jQuery version less than 1.8, since it deprecated in jQuery 1.8. Generally, the length property is preferred now.
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(".btn").click(function(){ alert($("li").size()); }); }); </script> </head> <body> <button class="btn">How many li elements?</button> <ol> <li>India</li> <li>US</li> <li>UK</li> <li>Australia</li> </ol> </body> </html>
jQuery length
The length property shows the number of elements in the jQuery object. Length does the same work of the size() method and avoids the overhead of a function call.
Example
You can try to run the following code to learn how to work with jQuery length property:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $(".btn").click(function(){ alert($("li").length); }); }); </script> </head> <body> <button class="btn">How many li elements?</button> <ol> <li>India</li> <li>US</li> <li>UK</li> <li>Australia</li> </ol> </body> </html>
- Related Articles
- What is Host, and what is the difference between Nutrients and Nutrition?
- What is the difference between Java and JavaScript?
- What is the difference between JavaScript and ECMAScript?
- What is the difference between JavaScript and C++?
- What is the difference between HTML tags and ?
- What is the difference between jQuery and JavaScript?
- What is the difference between jQuery and AngularJS?
- What is the difference between jQuery.show() and jQuery.hide()?
- What is the difference between jQuery.animate() and jQuery.hide()?
- What is the difference between = and: = assignment operators?
- What is the difference between time.clock() and time.time()?
- What is the difference between decodeURIComponent and decodeURI?
- What is the difference between == and === in JavaScript?
- What is the difference between session and cookies?
- What is the difference Between C and C++?

Advertisements