$checkbox
The $checkbox
utility object provides a set of methods for working with checkboxes, allowing you to manage and handle events for a list of checkboxes.
$checkbox(elements)
Creates a $checkbox
object for the specified list of checkboxes.
elements
(NodeList|Array|HTMLInputElement): The list of checkboxes or a single checkbox element.$checkbox
object with utility methods.checked()
Gets an array of checked checkboxes from the list.
change(caller)
Adds a change event listener to each checkbox in the list.
caller
(Function): The function to be called when a checkbox changes. The default is an empty function.<fieldset>
<legend>Choose your monster's features:</legend>
<div>
<input type="checkbox" id="scales" class="a" name="scales" checked />
<label for="scales">Scales</label>
</div>
<div>
<input type="checkbox" id="horns" name="horns" checked />
<label for="horns">Horns</label>
</div>
<div>
<input type="checkbox" id="horns" name="horns" />
<label for="horns">Horns</label>
</div>
<div>
<input type="checkbox" id="error" name="coooo" />
<label for="error">error</label>
</div>
<div>
<input type="checkbox" disabled="" id="guitar" name="guitar" />
<label for="guitar">Guitar disabled</label>
</div>
</fieldset>
// Example usage:
var checkboxList = document.querySelectorAll('input');
var checkboxes = $checkbox(checkboxList);
checkboxes.change(function (changedCheckbox, allCheckboxes, event) {
console.log('Checkbox changed:', changedCheckbox.checked);
console.log('All checkboxes:', allCheckboxes);
});
var checkedCheckboxes = checkboxes.checked(); //Array elements
console.log('Checked checkboxes:', checkedCheckboxes);
//or
var checkbox = $checkbox(document.querySelector('input'));
checkbox.change(function (changedCheckbox, allCheckboxes, event) {
console.log('Checkbox changed:', changedCheckbox.checked);
console.log('All checkboxes:', allCheckboxes);
});
var checkedCheckboxes = checkboxe.checked(); //Array elements
console.log('Checked checkboxes:', checkedCheckboxes);
toggle
Attribute DocumentationThe toggle
attribute is a custom attribute added to an <input>
element of type "checkbox" to enhance its appearance and behavior, creating a toggle switch. This custom attribute is used to indicate that the checkbox should be styled as a toggle switch.
<div>
<input toggle type="checkbox" id="scales" class="a" name="scales" checked />
<label for="scales">Scales</label>
</div>
In this example, the <input>
element has the toggle
attribute, which signifies that the checkbox should be visually presented as a toggle switch. The corresponding <label>
is associated with the checkbox using the for
attribute.
The checkbox component allows users to select or deselect options. Below are the variables you can customize to match your desired theme:
Variable | Description |
---|---|
--font-size |
Size of the checkbox. |
--border-style |
Style, width, and color of the checkbox border. |
--border-color |
Color of the checkbox border. |
--border-radius |
Border radius of the checkbox. |
--background-color |
Background color of the checkbox. |
--disabled-background |
Background color of the disabled checkbox. |
--disabled-opacity |
Opacity of the disabled checkbox. |
--color-secondary |
Secondary color used for the checkmark icon. |
Variable | Description |
---|---|
--font-size |
Size of the toggle switch. |
--color-primary |
Color of the toggle switch when checked. |
--color-secondary |
Secondary color used for the toggle switch knob. |
--ul-hover |
Background color of the toggle switch. |
--disabled-opacity |
Opacity of the disabled toggle switch. |
/* Checkbox */
input[type="checkbox"] {
/* Add your customizations here */
}
input[type="checkbox"]:disabled {
/* Add your customizations here */
}
input[type="checkbox"]:checked {
/* Add your customizations here */
}
/* Toggle Switch */
input[toggle][type="checkbox"] {
/* Add your customizations here */
}
input[toggle][type="checkbox"]:checked {
/* Add your customizations here */
}
input[toggle][type="checkbox"]:disabled {
/* Add your customizations here */
}
toggle
attribute is a custom attribute and does not have any built-in functionality. It is used as a marker for styling purposes.