Find tbody count
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);
}
}
精彩评论