I'm currently working on a form design and I would like to create a feature where the background color of each option alternates. This is similar to how you can style alternating rows in tables using CSS
tr:nth-child(even){background-color: #f2f2f2;}
In my attempts to achieve this effect, I experimented with using unique IDs that were linked to different CSS styles for displaying various 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++;
});
}
However, I discovered that the background color can only be changed within the form itself. Is there an alternative method to accomplish this desired effect?