Depending on which radio is checked i want to toggle two classes "leftChoice" and "rightChoice" Unfortunatelly the code wont work. Im trying to use pure JS without jQuery. Maybe there is an easier way to get the result.
var wrapper = document.getElementById('wrapper');
var choices = document.getElementsByName("choices");
var checkedChoice = "";
wrapper.classList.remove("rightChoice");
wrapper.classList.add("leftChoice");
choices.onchange(function() {
for (var i = 0, length = choices.length; i < length; i++) {
if (choices[i].checked) {
checkedChoice = choices[i].value;
break;
}
}
if(checkedChoice == "one"){
wrapper.classList.remove("rightChoice");
wrapper.classList.add("leftChoice");
}
else if(checkedChoice == "two"){
wrapper.classList.remove("leftChoice");
wrapper.classList.add("rightChoice");
}
});