Button Widgetversion added: 1.8
Description: Themeable buttons and button sets.
Button enhances standard form elements like buttons, inputs and anchors to themeable buttons with appropriate hover and active styles.
In addition to basic push buttons, radio buttons and checkboxes (inputs of type radio and checkbox) can be converted to buttons. Their associated label is styled to appear as the button, while the underlying input is updated on click. For the association to work properly, give the input an id
attribute, and refer to that in the label's for
attribute. Don't nest the input inside the label, as that causes accessibility problems.
In order to group radio buttons, Button also provides an additional widget, called Buttonset. Buttonset is used by selecting a container element (which contains the radio buttons) and calling .buttonset()
. Buttonset will also provide visual grouping, and therefore should be used whenever you have a group of buttons. It works by selecting all descendants and applying .button()
to them. You can enable and disable a button set, which will enable and disable all contained buttons. Destroying a button set also calls each button's destroy
method. For grouped radio and checkbox buttons, it's recommended to use a fieldset
with a legend
to provide an accessible group label.
When using an input of type button, submit or reset, support is limited to plain text labels with no icons.
Theming
The button widget uses the jQuery UI CSS framework to style its look and feel. If button specific styling is needed, the following CSS class names can be used:
-
ui-button
: The DOM element that represents the button. This element will additionally have one of the following classes depending on the text and icons option:ui-button-text-only
,ui-button-icon-only
,ui-button-icons-only
,ui-button-text-icons
.-
ui-button-icon-primary
: The element used to display the button's primary icon. This will only be present if a primary icon is provided in the icons option. -
ui-button-text
: The container around the textual content of the button. -
ui-button-icon-secondary
: The element used to display the button's secondary icon. This will only be present if a secondary icon is provided in the icons option.
-
-
ui-buttonset
: The outer container of Buttonsets.
Dependencies
Additional Notes:
- This widget requires some functional CSS, otherwise it won't work. If you build a custom theme, use the widget's specific CSS file as a starting point.
Options
disabled
false
true
.Initialize the button with the disabled
option specified:
1
2
3
|
|
Get or set the disabled
option, after initialization:
1
2
3
4
5
|
|
icons
{ primary: null, secondary: null }
Icons to display, with or without text (see text
option). By default, the primary icon is displayed on the left of the label text and the secondary is displayed on the right. The positioning can be controlled via CSS.
The value for the primary
and secondary
properties must match an icon class name, e.g., "ui-icon-gear"
. For using only one icon: icons: { primary: "ui-icon-locked" }
. For using two icons: icons: { primary: "ui-icon-gear", secondary: "ui-icon-triangle-1-s" }
.
Initialize the button with the icons
option specified:
1
2
3
|
|
Get or set the icons
option, after initialization:
1
2
3
4
5
|
|
label
null
null
), the element's HTML content is used, or its value
attribute if the element is an input element of type submit or reset, or the HTML content of the associated label element if the element is an input of type radio or checkbox.Initialize the button with the label
option specified:
1
2
3
|
|
Get or set the label
option, after initialization:
1
2
3
4
5
|
|
text
true
false
no text will be displayed, but the icons
option must be enabled, otherwise the text
option will be ignored.Initialize the button with the text
option specified:
1
2
3
|
|
Get or set the text
option, after initialization:
1
2
3
4
5
|
|
Methods
destroy()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the destroy method:
1
|
|
disable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the disable method:
1
|
|
enable()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the enable method:
1
|
|
option( optionName )Returns: Object
optionName
.-
optionNameType: StringThe name of the option to get.
Invoke the method:
1
|
|
option()Returns: PlainObject
- This signature does not accept any arguments.
Invoke the method:
1
|
|
option( optionName, value )Returns: jQuery (plugin only)
optionName
.-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
1
|
|
option( options )Returns: jQuery (plugin only)
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
1
|
|
refresh()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the refresh method:
1
|
|
widget()Returns: jQuery
jQuery
object containing the element visually representing the button.
- This method does not accept any arguments.
Invoke the widget method:
1
|
|
Events
create( event, ui )Type: buttoncreate
Note: The ui
object is empty but included for consistency with other events.
Initialize the button with the create callback specified:
1
2
3
|
|
Bind an event listener to the buttoncreate event:
1
|
|
Examples:
A simple jQuery UI Button
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
|
Demo:
A simple jQuery UI Buttonset
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
|