/** Vanilla javascript **/ // Get the value of the checked radio button, undefined on not checked or not found let radioButtonValue = (document.querySelector("input[name='radioName']:checked") || {}).value || undefined // Check radio button with value ... (document.querySelector("input[name='radioName'][value='A']") || {}).checked=true; /** jQuery **/ // Get the value of the checked radio button, undefined on not checked or not found let radioButtonValue = $("input[name='radioName']:checked").val(); // Check radio button with value ... $("input[name='radioName'][value='A']").prop('checked',true);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter