JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/redmond/jquery-ui.min.css">
<!-- By the setup on this website (JsFiddle.net), below external resources have been automatically loaded. -->
<!-- So, in you actual HTML code, uncomment the below relevant lines of code to load them accordingly -->
<!-- Load jQuery core library -->
<!--
<script type='text/javascript' src='http://code.jquery.com/jquery-2.1.4.min.js'></script>
-->
<!-- Load jQueryUI library -->
<!--
<script type='text/javascript' src='http://code.jquery.com/ui/1.11.4/jquery-ui.min.js'></script>
-->
<!-- Load jQueryUI Theme library (make either one effective) -->
<!--
<link rel="stylesheet" type="text/css" href='http://code.jquery.com/ui/1.11.4/themes/ui-lightness/jquery-ui.min.css'/>
<link rel="stylesheet" type="text/css" href='http://code.jquery.com/ui/1.11.4/themes/ui-darkness/jquery-ui.min.css'/>
<link rel="stylesheet" type="text/css" href='http://code.jquery.com/ui/1.11.4/themes/blitzer/jquery-ui.min.css'/>
<link rel="stylesheet" type="text/css" href='http://code.jquery.com/ui/1.11.4/themes/eggplant/jquery-ui.min.css'/>
<link rel="stylesheet" type="text/css" href='http://code.jquery.com/ui/1.11.4/themes/flick/jquery-ui.min.css'/>
<link rel="stylesheet" type="text/css" href='http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.min.css'/>
<link rel="stylesheet" type="text/css" href='http://code.jquery.com/ui/1.11.4/themes/sunny/jquery-ui.min.css'/>
<link rel='stylesheet' type='text/css' href='http://code.jquery.com/ui/1.11.4/themes/redmond/jquery-ui.min.css'>
-->
This webpage is primarily to demonstrate de-selectable radio boxes.
<h3 id='jquery-compatibility-error'>ERROR: It was detected that JavaScript or jQuery coding does not load properly, so some advance feature cannot be realised.</h3>
<h3>Style1: Raw (i.e. no styling/decoration):</h3>
<fieldset...
JavaScript
function selectiongrp_logicControl( s_selectiongrpName, b_useJQueryUiThemeToDecorate )
{
// Safeguard measure: If the mandatory function parameter is undefined or empty, nothing can be proceed further, so quit the current function with excit code:
if ( !s_selectiongrpName ) return -1;
// Define a constant for future use:
var ADF_THIS_IS_LAST_SELECTED='adf_this-is-last-selected';
// Hide the 'contingent select option item' and all its relevant ancillary objects (i.e. the label element):
$( '#' + s_selectiongrpName + '-option-X' ).hide();
$( '#' + s_selectiongrpName + '-option-X' ).next( 'label' ).hide();
// Decorate the selection group option items and their labels by applying the jQueryUI 'buttonset' function:
if( b_useJQueryUiThemeToDecorate ) $( '#jQueryUi-' + s_selectiongrpName).buttonset();
// Loop for each option item within the selection group:
$( 'input[name=' + s_selectiongrpName + ']' ).each( function()
{
// Define an 'onClick' event for every option item within the selection group:
$( this ).on( 'click', function()
{
// If the option item being clicked is the last selected one, then de-select such item.
// Two ways can achieve de-selection, apply either one below to adapt to your programming style or desired controller mechanism.
if( $( this ).attr( ADF_THIS_IS_LAST_SELECTED ) )
{
// Way[1]: Force selecting another item within the same selection group.
// This Way entails the 'contingent select option item'. So, if you consider such 'contingent select option item' is unnecessary/inappropriate to your programming style or controller mechanism, please don't choose this Way.
// (Note: Such 'contingent select option item' was deliberately hidden at the outset).
// $( '#' + s_selectiongrpName + '-option-X' ).prop( 'checked', true );
// Way[2]: Simply remove the current item's "checked" attribute:
$( this ).removeAttr( 'checked' );
// Both Way[1] and Way[2]: Remove the additional attribute...