Easy Tutorial
❮ Api Css Framework Api Selectable ❯

jQuery UI API - Spinner Widget

Category

Widgets

Usage

Description: Enhances a text input for entering numeric values, with up/down buttons and arrow key handling.

Version Added: 1.9

The Spinner, or number stepper control, is an ideal control for handling various numeric inputs. It allows users to directly enter a value or increment/decrement an existing value using the keyboard, mouse, or scroll wheel. When combined with Globalize, you can even spin to display different regional currencies and dates.

The Spinner uses two buttons to overlay the text input with increment and decrement values of the current value. It adds key events to allow the same increment and decrement with the keyboard. The Spinner represents the numeric formatting and parsing of Globalize.

Keyboard Interaction

After clicking the spinner buttons with the mouse, the focus remains on the text field.

When the Spinner is not read-only (<input readonly>), users can enter values, which may result in invalid values (less than the minimum, greater than the maximum, mismatched increments/decrements, non-numeric input). When incrementing or decrementing, whether programmatically or via the spinner buttons, the value is forced to a valid value (for more details, see the descriptions of stepUp() and stepDown()).

Theming

The Spinner Widget uses the jQuery UI CSS Framework to define its appearance and style. To use the styles specific to the Spinner, you can use the following CSS class names:

Dependencies

Additional Notes

Example

A standard number spinner.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Spinner Widget Demo</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
<body>

<input id="spinner">

<script>
$( "#spinner" ).spinner();
</script>

</body>
</html>

View Demo

❮ Api Css Framework Api Selectable ❯