Count immediate child div elements using jQuery

后端 未结 12 2107
无人共我
无人共我 2020-11-28 01:19

I have the following HTML node structure:

<
相关标签:
12条回答
  • 2020-11-28 02:03
    $("div", "#superpics").size();
    
    0 讨论(0)
  • 2020-11-28 02:04
    $('#foo').children('div').length
    
    0 讨论(0)
  • 2020-11-28 02:05
    $("#foo > div").length
    

    Direct children of the element with the id 'foo' which are divs. Then retrieving the size of the wrapped set produced.

    0 讨论(0)
  • 2020-11-28 02:06
    $('#foo > div').size()
    
    0 讨论(0)
  • 2020-11-28 02:07
    $("#foo > div").length
    

    jQuery has a .size() function which will return the number of times that an element appears but, as specified in the jQuery documentation, it is slower and returns the same value as the .length property so it is best to simply use the .length property. From here: http://www.electrictoolbox.com/get-total-number-matched-elements-jquery/

    0 讨论(0)
  • 2020-11-28 02:09

    With the most recent version of jquery, you can use $("#superpics div").children().length.

    0 讨论(0)
提交回复
热议问题