You could loop through each question (<h1>
) and looking through it's answers using .nextUntil()
with .filter()
to see if there any :checked
ones, like this:
var noAns = $("h1").filter(function() {
return $(this).nextUntil("h1").filter(":checked").length == 0;
});
This would return all the questions with no radio selected for them, you could check the .length
of that if you wanted to see if any don't have answers, for example:
if(noAns.length > 0) {
alert(noAns.length + " question(s) don't have answers!");
}
You can give it a try here.
You can also extend this a bit, for example highlighting the questions that were missed:
if(noAns.css({ color: "red" }).length > 0) {
and use $("h1").css({ color: "" })
to clear it the next round, you can give it a try here.