I'm trying to use a bit of JS to add the CSS class "alt" to alternating lis on my menu, so I can style them with a different color. I worked on a site previously and one of the programmers told me he used this bit of code to accomplish this, so there is precedent. I've placed it in the head section:
<script type="text/javascript">
$('#nav-right ul li:nth-child(odd)').addClass('alt');
$('#nav ul li:nth-child(odd)').addClass('alt');
</script>
Unfortunately, it doesn't do a thing. The reason I'm asking in this forum instead of a JS one is because WP is already adding about a million class to the menu already, and I was wondering if somehow that interferes with what I'm trying to do. I thought maybe this script would just throw in "alt" with all the other classes that were already there, but apparently not. I've also tried different, more specific CSS within the code (e.g., $('#nav-right ul#menu-primary-navigation li:nth-child(odd)').addClass('alt');), thinking maybe I just wasn't be specific enough about my target, but no luck.
Any idea how to make this work?