<script type="text/javascript">
window.onload = function(){
var li = document.getElementById('ul').getElementsByTagName('li'), i = li.length;
while(i--) {
li[i].style.backgroundColor = i%2 ? 'red' : 'green';
}
};
</script>
<ul id="ul">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
</ul>