Count number of img tags inside a div tag

前端 未结 10 1948
暗喜
暗喜 2021-02-04 05:29

My code goes like this.

相关标签:
10条回答
  • 2021-02-04 05:53

    Try to get them like this:

    var count = $("#some_id img").length;
    
    0 讨论(0)
  • 2021-02-04 05:58

    Use:

    $("#some_id img").length
    

    Here's a fiddle of it.

    0 讨论(0)
  • 2021-02-04 06:00

    Also (even though there are many right answers here), every of these methods in jQuery, such as children(), siblings(), parents(), closest(), etc. accept a jQuery selector as a parameter.

    So doing

    $("#some_id").children("img").length

    should return what you need as well.

    0 讨论(0)
  • 2021-02-04 06:05

    use this

    $("#some_id img").length
    
    0 讨论(0)
提交回复
热议问题