I am trying to add the class “current” to whatever radio option is currently selected. I can use
onClick="document.getElementById('volunteering').class += 'current';"
However, this will indeed add the class, but it sticks when you select another radio button (because it’s on each button). Any thoughts on how to implement it across all radio buttons?
Here is the code I am using:
<form>
<ul>
<input type="radio" name="category" id="volunteering" value="volunteering"><li class="conversation">
<a href="#" onClick="document.getElementById('volunteering').checked = true;" >Volunteering</a>
</li>
<input type="radio" name="category" value="cityproblems" id="cityproblems"><li class="conversation">
<a href="#" onClick="document.getElementById('cityproblems').checked = true;" >City Problems</a>
</li>
<input type="radio" name="category" value="safety" id="safety"><li class="conversation">
<a href="#" onClick="document.getElementById('safety').checked = true;" class="">Safety</a>
</li>
</form>
You need to first remove that class from all radio buttons, then add it back to the clicked one. Define a function that does this by receiving the id as a parameter, and bind that to the
onclick.Then bind each radio button’s
onclickusing: