jQuery size() methodThe size() method is used to return the number of elements in the jQuery object. 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. The length property is also preferred because it avoids an extra function call, so it is quicker than the size() function. SyntaxThe size() method doesn't accept any argument. Now, let's see an example to understand the working of the size() function. ExampleIn this example, we are not using the latest version of jQuery. We are using the jQuery version 1.6.1, which is before 1.8. It is because the size() method is deprecated in jQuery version 1.8. Here, there are three paragraph elements. We are using the size() method to count the number of paragraph elements. On clicking the button, an alert box will be displayed that will show the total number of paragraph elements. Test it NowOutput After the execution of the above code, the output will be - After clicking the button, the output will be - Next TopicjQuery contains() method |