Skip to content

Instantly share code, notes, and snippets.

@rockbot
Forked from iamdustan/add-even-class.js
Created September 28, 2012 14:59
Show Gist options
  • Save rockbot/3800387 to your computer and use it in GitHub Desktop.
Save rockbot/3800387 to your computer and use it in GitHub Desktop.
the power of dom utilities and selector engines
// the power of dom utilities and selector engines
// $('table.projects tr:even').addClass('even-row');
var slice = Array.prototype.slice,
toArray = function (obj) {
return Array.prototype.slice.call(obj, 0)
}
var tables = toArray(document.querySelectorAll('table.projects'))
tables.forEach(function(tableEl) {
var rows = toArray(tableEl.querySelectorAll('>tr'))
rows.forEach(function(rowEl, i) {
if (i%2)
rows.classList.add('even-row')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment