How can I change the number of events triggered when clicking a label
without directly selecting the input element?
Is there a way to achieve this using CSS only, or is it necessary to use JavaScript like
document.querySelector('label input')
?
Run the code snippet below and observe the console output while switching between steps to see the current behavior of triggering two events.
document.querySelector('input[name=step]').onclick = e => console.log(e.target)
label {
cursor: pointer;
color: grey;
font-size: large;
}
input[type=radio] {
display: none;
}
input[type=radio]:checked ~ * {
color: blue;
font-weight: bold;
}
<label><input type="radio" name="step"><span>Step 1</span></label>
<label><input type="radio" name="step"><span>Step 2</span></label>