• Blogs (9)
    • 📱 236 - 992 - 3846

      đź“§ jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • jQuery length property

    Blogs20122012-07-04


    jQuery length property

    The jQuery .length property counts the number of elements in the jQuery object. It does the same way JavaScript counts array length. jQuery objects aren’t the only things that can have a length property. Strings and arrays have a length property, too.

    The usage:
    $(element).length -> The number of elements currently matched. Generally test if the element exists, for examples:

    if($('#divid').length==0)
      --> jQuery object property: <div id="divid"> exists?
    
    if($('#divid').html().length>0)
      --> String length: <div id="divid" /> include contents?

    The above example is useful: they are frequently used in jQuery contexts.