jquery count elements with attribute

前端 未结 3 1633
南笙
南笙 2020-12-10 11:58

Can I count the number of elements with a specific attribute?

For example all the images with the src attribute test.gif

3条回答
  •  失恋的感觉
    2020-12-10 13:04

    Use the CSS attribute selectors to filter on the attribute

    $("img[src='test.gif']").length;
    

    the size() and length both returns the number of elements matched;

提交回复
热议问题