General Date & Time pickers Event Calendar Form components Responsive list Numeric pickers Pickers & dropdowns Layout & navigation Tools Accessibility

Switch

Switches are bascially also checkboxes, but with a different style. To make a switch, add the data-role="switch" attribute to a checkbox.

Wrapped in label element
<label>
    I agree
    <input id="agree" type="checkbox" data-role="switch"/>
</label>
Wrapped in div element
<div>
    <label for="agree">I agree</label>
    <input id="agree" type="checkbox" data-role="switch"/>
</div>
With description
<label>
    I agree
    <span class="mbsc-desc">Sample description</span>
    <input id="agree" type="checkbox" data-role="switch"/>
</label>

For many more examples - simple and complex use-cases - check out the switch demos for javascript.

Options

Name Description
checked If an input element has the checked attribute, the element will be pre-selected (checked) when the page loads.
data-enhance If a form element has the data-enhance="false" attribute, the particular element won't be enhanced.
data-role If a checkbox input has the data-role="switch" attribute, it will be transformed into a switch.
disabled If an element has the disabled attribute, the element will be disabled.

Methods

Name Description
getVal() Returns the state of the switch (true/false).

Returns: Boolean

  • The state of the switch value.

Example

Methods can be called on an instance. For more details see calling methods
mobiscrollInstance.getVal();
setVal(value) Sets the state of the switch (true/false).

Parameters

  • value: Boolean - The state of the switch value.

Example

Methods can be called on an instance. For more details see calling methods
mobiscrollInstance.setVal(false);