JSFiddle - React, Tailwind, and code Playground

by CJ Ramki

HTML

<p>radio elements:
    <input type="radio" name="elemainfoto" id="first" value="1" checked = "true"/>element 1
    <input type="radio" name="elemainfoto" id="second" value="2" />element 2
    <input type="radio" name="elemainfotor" id="thrid" value="3" />element 3</p>

JavaScript

$(function () {
    $("input:radio[name=elemainfoto]:first").attr('checked', true);
    
    $('input[type="radio"]').click(function () {
        if ($(this).is(':checked')) {
            if ($(this).val() == '1') alert('first radio element is checked');
            if ($(this).val() == '2') alert('second radio element is checked');
            if ($(this).val() == '3') alert('third radio element is checked');
        }
    });
});