I have a list that has 2 radio buttons against it. I need to randomly select radio buttons in that list. Each radio button (rb1: yes and rb2: no) has different ids. Here's my code.
$("#rbList").each(function () {
var radios = $(this).find("input[type=radio]");
if (radios.length > 0) {
var randomnumber = Math.floor(Math.random() * radios.length);
$(radios[randomnumber]).trigger('click');
}
});
This works to select one radio button in the group. What I don't understand is how to loop it to randomly select all the radio buttons in the list (be it either yes or no). What do I have to add? Also, I need to automate that. Like just hit enter in console and it should reflect on the page. Any help is greatly appreciated. Thank you.