I have the following HTML radio buttons and I need to add 'checked' as the class of the label when the relevant radio button is selected. The code below works for clicks, but I also need the class added if one of the buttons is selected without clicking, i.e. if the radio button was already selected when the page loaded.
<label><input name="radio" type="radio">One</label><br/>
<label><input name="radio" type="radio">Two</label>
Here's the js:
$(document).ready(function(){
$('label').click(function(){
$('label').removeClass('checked');
$(this).addClass('checked');
});
});
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments