How can I count the number of children?

后端 未结 5 1927
北荒
北荒 2020-11-27 04:57

I have a list

  • ...

I need jQuery to count the number of items in my list.

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 05:35

    You can do this using jQuery:

    This method gets a list of its children then counts the length of that list, as simple as that.

    $("ul").find("*").length;
    

    The find() method traverses DOM downwards along descendants, all the way down to the last descendant.

    Note: children() method traverses a single level down the DOM tree.

提交回复
热议问题