Published in: JavaScript
This script will allow you to alternately place a style on objects (in this example, every other list item).
function stripeElement(objects, className) { for (var i = 0; i < objects.length; i++) { if (i % 2) { objects[i].className += ' ' + className; } } } window.onload = function() { if (document.getElementById('list')) { js_lib.css.mod.stripeElement(document.getElementById('list').getElementsByTagName('li'), 'tint'); } }
Comments
Subscribe to comments
You need to login to post a comment.

Your for loop could probably be better written as:
That way you wouldn't have to nest an "if" condition in the loop.