开发者

Find tbody count

开发者 https://www.devze.com 2023-02-01 18:11 出处:网络
I\'m using a for loop to populate html table. 开发者_开发知识库How can I get the count of the all the tbody tags in tables based on its className?

I'm using a for loop to populate html table. 开发者_开发知识库How can I get the count of the all the tbody tags in tables based on its className?

Sorry might be dumb question but couldn't find how ?


If you are using jQuery, you can do this way:

alert($('tbody.yourClass').length);

Or vanilla Javascript:

var els = document.getElementsByTagName('tbody');

var counter = 0;
for(var i = 0; i < els.length; i++){
  if (els[i].className === 'yourClass') counter++;
}

alert(counter);


In case you are not using jQuery you can try the one below:

var a = document.getElementsByTagName("TBODY");
    var len = a.length;
    var resultArr = [];
    var tBodyClassName = "something" //You can update it your className.
    for(var i=0; i<len; i++)
    {
        var b = resultArr[i];
        if(b.className == tBodyClassName)
        {
            resultArr.push(b);
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号