-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
Description
Instead of adding or removing a class, the checked state of the referenced element is toggled, or set to a predefined boolean if the optional force argument is provided.
The target usage are HTML toggles for CSS rules: A checkbox controls the styles in an adjacent sibling div. Best practice, though not mainstream due to JS prevalence.
We need the toggleChecked() action as using <label> would prevent propagating the click to an enclosing anchor, and conversely we cannot check a box when tapping on a nested anchor element.
Alternatives Considered
The toggleClass() action as a workaround fails when JS is turned off. The checkbox cannot be nested in <noscript> as this disrupts the adjacent sibling combinator. Also, noscript elements are typically repurposed in AMP environments to provide a fallback experience regardless whether JS is actually turned off.