I'm making a simple form and want to alternate the background color of each option like you can for tables using CSS tr:nth-child(even){background-color: #f2f2f2;}
For the form I tried using ids that linked to CSS with different background colors:
function options(){
var i =0;
var name;
$(xmlDoc).children().children().each(function(){
name = $(this).children().first().text();
if(i % 2 == 0){
$('form').append(" <input type='checkbox' id=odd'" + "value=" + name + ">"+ name + "<br>");
}
else{
$('form').append(" <input type='checkbox' id='even'" + "value=" + name + ">"+ name + "<br>");
}
i++;
});
}
but have found that you can only change the background color by indicating it in the form. Is there any other way to do this?