Created
May 12, 2015 12:56
-
-
Save israeljrs/6b87cf68db2cb804711f to your computer and use it in GitHub Desktop.
JavaScript add a Even ,odd class in your listing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul id="list"> | |
<li>Item 1</li> | |
<li>Item 2</li> | |
<li>Item 3</li> | |
<li>Item 4</li> | |
<li>Item 5</li> | |
<li>Item 6</li> | |
</ul> | |
<script> | |
var IdRef = document.getElementById("list"); | |
var IdChild = IdRef.getElementByTagName("li"); | |
for (i=0; i<IdChild.length; i++) { | |
if(i%2 == 0) { | |
IdChild[i].classList.add('even'); | |
} else { | |
IdChild[i].classList.add('odd'); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment