Radio button selection on jquery tabs label click
By : sibi elango
Date : March 29 2020, 07:55 AM
|
Screen-reader friendly way to label a checkbox / radio button, that is already using a label to be click-able
By : Ron Cohen
Date : March 29 2020, 07:55 AM
|
How to stretch label over a custom div to achieve radio button click
By : Dewei Sun
Date : March 29 2020, 07:55 AM
|
radio button selection remove after click on other group of radio box
By : omer
Date : March 29 2020, 07:55 AM
|
Reset radio selection from <label> click
By : kapobajza
Date : March 29 2020, 07:55 AM
I wish this help you It's ugly but I think I've got it. The click event for the radio button fires when the label is clicked. Use the mousedown of the label to capture the current state of the radio button. Then in the event handler for the radio button, check this state and untoggle as required. code :
window.onload = function() {
document.querySelectorAll('ul li > input + label').forEach(function(rd) {
rd.addEventListener("mousedown",
function() {
//store if we need to toggle as a data attribute on the radio button
this.previousElementSibling.dataset.uncheck = this.previousElementSibling.checked;
});
});
document.querySelectorAll('ul li > input[type=radio]').forEach(function(rd) {
rd.addEventListener("click", function() {
var tog = this.checked && this.dataset.uncheck === "true";
console.log(this);
//Check the data attribute
if (tog == true) {
this.checked = false;
}
});
});
};
<nav id="lcn-dropdown">
<input type="checkbox" id="main-drop">
<label for="main-drop" id="toggle-main">▾</label>
<ul id="main-list">
<li>
<input type="radio" id="1-1-radio" name="1-menu">
<label for="1-1-radio" class="sub-toggle"> A00-A08 ▸</label>
<ul class="side-from-1">
<li><a href="#"> A00 ALIS ▸</a>
<!--<ul class="side-from-1">
<li><a href ="#" class="third"> A00100 Test</a></li>
<li> <a href ="#"> XXXXXX</a></li>
<li> <a href ="#" class="last"> XXXXXX</a></li>
</ul>-->
</li>
<li><a href="#"> A01 Documentation ▸</a></li>
<li><a href="#"> A03 Servicing ▸</a></li>
<li><a href="#"> A05 General ▸</a></li>
<li><a href="#"> A07 Testing ▸</a></li>
<li><a href="#" class="last"> A08 Testing ▸</a></li>
</ul>
</li>
</ul>
</nav>
|