Use jQuery to clone list item with alternate colors when link is clicked -


what easiest way alternate color of cloned list item?

every time link clicked list item cloned , added bottom of list, every other item on list should have class 'highlight' added.

this link fiddle have done except alternating color part.

this example how produced html should like:

<ul>   <li>some text</li>   <li class="highlight">some text</li>   <li>some text</li>   <li class="highlight">some text</li>   <li>some text</li>   <li class="highlight">some text</li> </ul> 

thanks!

<a href="#">add more</a> <ul>     <li>some text</li> </ul>      $('a').click(function() {     var link = $('ul li:first').clone();     if($('ul li').length % 2 != 0) {         link.addclass("highlight");     }     link.appendto('ul');     return false; }); 

Comments