Button

A button that can be pressed by the user. Event handlers can be used to trap mouse, keyboard and other events. It is typically rendered as a grey outset rectangle. You can specify the label of the button using the label attribute or by placing content inside the button.

More information about button

Example:

    <button label="Press Me"
            oncommand="alert('You pressed me!'); return false;"/>

The button element implements the following interfaces:

nsIAccessibleProvider   nsIDOMXULButtonElement  

Attributes:

accesskey autoCheck checkState checked command
crop dir disabled dlgType group
icon image label open orient
tabindex type

Properties and Methods:

accessKey accessible autoCheck checkState checked
command crop dir disabled dlgType
group image label open orient
tabIndex type

Attributes:

Inherited from XUL Element:

align
allowevents
allownegativeassertions
class
coalesceduplicatearcs
collapsed
container
containment
context
contextmenu
datasources
dir
empty
equalsize
flags
flex
height
hidden
id
insertafter
insertbefore
left
maxheight
maxwidth
menu
minheight
minwidth
mousethrough
observes
ordinal
orient
pack
persist
popup
position
preference-editable
ref
removeelement
sortDirection
sortResource
sortResource2
statustext
style
template
tooltip
tooltiptext
top
uri
wait-cursor
width

accesskey

Type: character

This should be set to a letter that is used as a shortcut key. This letter should be one of the characters that appears in the label text for the button. This letter will typically be drawn underlined, although this behavior will be platform and theme specific. When the user presses ALT (or a similar key that varies on each platform) and the access key, the button will be activated from anywhere in the window. Although the value is case insensitive, a letter with the case matching the accesskey attribute will used if both cases exist in the label.

autoCheck

Type: boolean

If this attribute is true, or left out, the checked state of the button will be switched each time the button is pressed. If this attribute is false, the checked state must be adjusted manually.

checkState

Type: integer: 0, 1 or 2

This attribute may be used to create three state buttons, numbered 0, 1 and 2. When in state 0 or 1, pressing the button will switch to the opposite state. When in state 2, pressing the button will switch to state 0. This means that the button acts like a checkbox except that there is a third state which must be set manually by adjusting the check state. If you wish to have different behavior for how the states are adjusted, set the autoCheck attribute to false and adjust the state with a script. The type attribute must be set to 'checkbox' for buttons with a check state. Constants for the possible values for this attribute are in the nsIDOMXULButtonElement interface.

checked

Type: boolean

Indicates whether the button is checked or not.

command

Type: element id

Set to the id of a command element that is being observed by the element.

crop

Type: one of the values below

If the label of the button is too small to fit in its given space, the text will be cropped on the side specified by the crop attribute. An ellipsis will be used in place of the cropped text. If the box direction is reversed, the cropping is reversed.

dir

Type: one of the values below

Specifies which side of the button's label that its image is placed.

disabled

Type: boolean

Indicates whether the button is disabled or not. If this attribute is set to true, the button is disabled. This is usually drawn with the text in grey. If the button is disabled, it does not respond to user actions. The element cannot be focused and the command event will not fire. The element will still respond to mouse events. To enable the button, leave the attribute out entirely as opposed to setting the value to false.

dlgType

Type: one of the values below

The dialog type of the button, used only when the button is in a dialog box. You can use this feature to replace the standard dialog box buttons with custom buttons, yet the dialog event methods will still function. For example, if the dlgType is set to 'accept', the button will replace the dialog box's accept button, which is usually labeled OK. Using this attribute on a button that is not in a dialog box has no effect. The following values can be used as the dialog type:

group

Type: string group name

Buttons with the same value for their group attribute are put into the same group. Only one button from each group can be checked at a time. If the user selects one the radio buttons, the others in the group are unchecked.

icon    Mozilla 1.8

This attribute should be used to set the usage for common buttons. Some platforms display these buttons with a small icon indicating their usage. This should be used in place of the image attribute. Possible values include: accept, cancel, help, open, save, find, clear, yes, no, apply, close, print, add, remove, refresh, go-forward, go-back, properties, select-font, select-color, network. If you are using a button that matches one of these common usages, use the icon attribute to indicate this.

image

Type: image URL

The URL of the image to appear on the button. If this is attribute is left out, no image appears. The position of the image is determined by the dir and orient attributes.

label

Type: string

The label that will appear on the button. If this is left out, no text appears.

open

Type: boolean

For the menu type buttons, the open attribute is set to true when the menu is open. The open attribute is not present if the menu is closed.

orient

Type: one of the values below

Along with the dir attribute, the orient attribute is used to indicate where the button's image appears in relation to the the label.

tabindex

Type: integer

The tab order of the element. The tab order is the order in which the focus is moved when the user presses the Tab key. Elements with a higher tabindex are later in the tab order sequence.

type

Type: one of the values below

The type of button. If this attribute is not present, a normal button is created. Leave the attribute out for a normal button.


Properties and Methods:

Inherited from XUL Element:

align
allowEvents
blur
boxObject
boxObject.element
boxObject.getLookAndFeelMetric
boxObject.height
boxObject.screenX
boxObject.screenY
boxObject.width
boxObject.x
boxObject.y
builder
className
click
collapsed
contextMenu
controllers
database
datasources
dir
doCommand
flex
focus
getElementsByAttribute
height
hidden
id
left
maxHeight
maxWidth
menu
minHeight
minWidth
observes
ordinal
orient
pack
persist
ref
resource
statusText
style
tooltip
tooltipText
top
width

Inherited from Element:

addEventListener
appendChild
attributes
childNodes
cloneNode
dispatchEvent
firstChild
getAttribute
getAttributeNS
getAttributeNode
getAttributeNodeNS
getElementsByTagName
getElementsByTagNameNS
hasAttribute
hasAttributeNS
hasAttributes
hasChildNodes
insertBefore
isSupported
lastChild
localName
namespaceURI
nextSibling
nodeName
nodeType
nodeValue
normalize
ownerDocument
parentNode
prefix
previousSibling
removeAttribute
removeAttributeNS
removeAttributeNode
removeChild
removeEventListener
replaceChild
setAttribute
setAttributeNS
setAttributeNode
setAttributeNodeNS
tagName

accessKey

Type: character

Gets and sets the value of the accesskey attribute.

accessible

Type: nsIAccessible

Returns the accessibility object for the button.

autoCheck

Type: boolean

Gets and sets the value of the autoCheck attribute.

checkState

Type: integer: 0, 1 or 2

Gets and sets the value of the checkState attribute.

checked

Type: boolean

Gets and sets the value of the checked attribute.

command

Type: element id

Gets and sets the value of the command attribute.

crop

Type: string

Gets and sets the value of the crop attribute.

dir

Type: string

Gets and sets the value of the dir attribute.

disabled

Type: boolean

Gets and sets the value of the disabled attribute.

dlgType

Type: string

Gets and sets the value of the dlgType attribute.

group

Type: string group name

Gets and sets the value of the group attribute.

image

Type: image URL

Gets and sets the value of the image attribute.

label

Type: string

Gets and sets the value of the label attribute.

open

Type: boolean

Gets and sets the value of the open attribute.

orient

Type: string

Gets and sets the value of the orient attribute.

tabIndex    Mozilla 1.8

Type: integer

Gets and sets the value of the tabindex attribute.

type

Type: string

Gets and sets the value of the type attribute.


Copyright (C) 1999 - 2004 XulPlanet.com