For my quiz on test practice with an array of questions, each question includes five radio buttons, but only one is correct. Initially, all five options have a gray background. Upon selecting a wrong option, it changes to red. If another incorrect option is chosen, the new one turns red while the previous one reverts to gray. However, upon choosing the correct answer, it switches to green while the rest remain gray.
$(document).ready(function() {
$("input[value='wrong']").click(function() {
$("label").css("background-color", "red");
});
$("input[value='right']").click(function() {
$("label").css("background-color", "green");
});
});
.option {
background: #eee;
display: block;
padding: 5px 10px 5px;
color: #000;
text-decoration: none;
-moz-border-radius: 6px;
-webkit-border-radius: 6px;
-khtml-border-radius: 6px;
border-radius: 6px;
box-shadow: inset 0px 1px 3px rgba(0, 0, 0, 0.6);
-moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.6);
-webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.6);
text-shadow: 0px -1px 1px rgba(0, 0, 0, 0.25);
border-bottom: 1px solid rgba(0, 0, 0, 0.25);
position: relative;
cursor: pointer;
text-decoration: none;
margin-bottom: 10px;
}
input[type="radio"] {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form class="form3">
<input type="radio" name="option" value="wrong" class="option1">
<label class="option">Option 1</label>
<input type="radio" name="option" value="wrong" class="option2">
<label class="option">Option 2</label>
<input type="radio" name="option" value="wrong" class="option3">
<label class="option">Option 3</label>
<input type="radio" name="option" value="right" class="option4">
<label class="option">Option 4</label>
<input type="radio" name="option" value="wrong" class="option5">
<label class="option">Option 5</label>
</form>
How do I achieve this functionality using JQuery?