JSFiddle - React, Tailwind, and code Playground
HTML
<div id='container'>
<input type="radio" name="test" value="1"> Option 1<br />
<input type="radio" name="test" value="2"> Option 2<br />
<input type="radio" name="test" value="3"> Option 3<br />
<input type="radio" name="test" value="4"> Option 4<br />
<input type="radio" name="test" value="5"> Option 5<br />
</div>
<input id='result' type='text'><button>Show active</button>
CSS
#container {
margin: 20px;
}
JavaScript
$(function() {
$('[name="test"]').each(function() {
$(this).mousedown(function(e) {
e.preventDefault();
if ($(this).is(':checked')) {
console.log('This radio button was checked in mousedown');
} else {
console.log('This radio button was not checked in mousedown');
}
});
$(this).click(function(e) {
e.preventDefault();
if ($(this).is(':checked')) {
console.log('This radio button was checked');
} else {
console.log('This radio button was not checked');
}
});
$(this).mouseup(function(e) {
e.preventDefault();
if ($(this).is(':checked')) {
console.log('This radio button was checked in mouseup');
} else {
console.log('This radio button was not checked in mouseup');
}
});
});
$('button').click(function(e){
$('#result').val('');
$('[name="test"]').each(function(){
if($(this).is(':checked')){
$('#result').val($('#result').val() + $(this).val() + ' ');
}
});
});
});