Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What is the difference between jquery.size() and jquery.length ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 535
    Comment on it

    Hello Readers,

    In jquery both works and gives the same result but now the time in current version of jquery we use the jquery.length because jquery.size is depreciated.

    Below is the some points about this properties :

    1. jquery.size() and jquery.length() both returns the number of element in an object.

    2. jquery.length() property is faster as compared to jquery.size() method.

    3. jquery.length() property prefered compared to size() because it does not have overhead of a function call.

    4. Very significant difference is that jquery.size() is depreciated so we always use jquery.length() instead of jquery.size().

    5. For Examples: Counts the number of unordered list li on the page to demonstrate the same according to the jQuery documentation.

      $('li').size();

      $('li').length;// faster

    In the above example, says that the jquery.length() property should be prefered over the jquery.size() function and it does not overhead the function call so it become faster as compared to size()

    1. jquery.size() method does not accept any arguments.

    1. Below is the another example (simple unordered list on the page):
    2. Example

      <ul>
        <li>foo</li>
        <li>bar</li>
      </ul>
      

      Both .size() and .length identify the number of items :

      alert( "Size: " + $( "li" ).size() );
      
      alert( "Size: " + $( "li" ).length );
      

      This results in two alerts :

      Size: 2

      Size: 2

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: