I try to write these code to make grid view through CSS:( jsbin )
var tables = document.getElementsByClassName('tableData');
var rows = tables[0].getElementsByTagName('tr');
for(var i = 1; i < rows.length; i += 2) {
alert(rows[i]);
rows[i].className = "alt";
}
This only works with the tr elements has class=""
. But if I want to add class to tr.
I've tried Core.addClass
but it doesn't work.
Two years later (2012/06), there is a new and shiny approach - element.classList
with methods add()
, remove()
, toggle()
, contains()
.
rows[i].classList.add("alt");
Supported by
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With