Counting div elements based on id

前端 未结 2 1613
鱼传尺愫
鱼传尺愫 2021-01-29 05:02

I have a page similar to:

2条回答
  •  孤独总比滥情好
    2021-01-29 05:21

    jQuery:

    $("div[id]").filter(function() {
        return !(/^box:content:\d+:text$/.test(this.id));
    }).size();
    

    Pure JavaScript:

    var elems = document.getElementsByTagName("div"),
        count = 0;
    for (var i=0, n=elems.length; i

提交回复
热议问题