Blame | Last modification | View Log | RSS feed
<ul class="UIAPIPlugin-toc">
<li><a href="#overview">Overview</a></li>
<li><a href="#options">Options</a></li>
<li><a href="#events">Events</a></li>
<li><a href="#methods">Methods</a></li>
<li><a href="#theming">Theming</a></li>
</ul>
<div class="UIAPIPlugin">
<h1>jQuery UI Button</h1>
<div id="overview">
<h2 class="top-header">Overview</h2>
<div id="overview-main">
<p>Button enhances standard form elements like button, input of type submit or reset or anchors to themable buttons with appropiate mouseover and active styles.</p>
<p>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.</p>
<p>In order to group radio buttons, Button also provides an additional widget-method, called Buttonset. Its 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 descendents and applying button() to them. You can enable and disable a buttonset, which will enable and disable all contained buttons. Destroying a buttonset also calls the button's destroy method.</p>
<p>When using an input of type button, submit or reset, support is limited to plain text labels with no icons.</p>
</div>
<div id="overview-dependencies">
<h3>Dependencies</h3>
<ul>
<li>UI Core</li>
<li>UI Widget</li>
</ul>
</div>
<div id="overview-example">
<h3>Example</h3>
<div id="overview-example" class="example">
<ul><li><a href="#demo"><span>Demo</span></a></li><li><a href="#source"><span>View Source</span></a></li></ul>
<p><div id="demo" class="tabs-container" rel="300">
A simple jQuery UI Button.<br />
</p>
<pre>$("button").button();
</pre>
<p></div><div id="source" class="tabs-container">
</p>
<pre><!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("button").button();
});
</script>
</head>
<body style="font-size:62.5%;">
<button>Button label</button>
</body>
</html>
</pre>
<p></div>
</p><p></div>
<div id="overview-example" class="example">
<ul><li><a href="#demo"><span>Demo</span></a></li><li><a href="#source"><span>View Source</span></a></li></ul>
<div id="demo" class="tabs-container" rel="300">
A simple jQuery UI Button.<br />
</p>
<pre>$("#radio1").buttonset();
</pre>
<p></div><div id="source" class="tabs-container">
</p>
<pre><!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#radio1").buttonset();
});
</script>
</head>
<body style="font-size:62.5%;">
<div id="radio1">
<input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
<input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
<input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
</div>
</body>
</html>
</pre>
<p></div>
</p><p></div>
</div>
</div>
<div id="options">
<h2 class="top-header">Options</h2>
<ul class="options-list">
<li class="option" id="option-disabled">
<div class="option-header">
<h3 class="option-name"><a href="#option-disabled">disabled</a></h3>
<dl>
<dt class="option-type-label">Type:</dt>
<dd class="option-type">Boolean</dd>
<dt class="option-default-label">Default:</dt>
<dd class="option-default">false</dd>
</dl>
</div>
<div class="option-description">
<p>Disables (true) or enables (false) the button. Can be set when initialising (first creating) the button.</p>
</div>
<div class="option-examples">
<h4>Code examples</h4>
<dl class="option-examples-list">
<dt>
Initialize a button with the <code>disabled</code> option specified.
</dt>
<dd>
<pre><code>$( ".selector" ).button({ disabled: true });</code></pre>
</dd>
<dt>
Get or set the <code>disabled</code> option, after init.
</dt>
<dd>
<pre><code>//getter
var disabled = $( ".selector" ).button( "option", "disabled" );
//setter
$( ".selector" ).button( "option", "disabled", true );</code></pre>
</dd>
</dl>
</div>
</li>
<li class="option" id="option-text">
<div class="option-header">
<h3 class="option-name"><a href="#option-text">text</a></h3>
<dl>
<dt class="option-type-label">Type:</dt>
<dd class="option-type">Boolean</dd>
<dt class="option-default-label">Default:</dt>
<dd class="option-default">true</dd>
</dl>
</div>
<div class="option-description">
<p>Whether to show any text - when set to false (display no text), icons (see icons option) must be enabled, otherwise it'll be ignored.</p>
</div>
<div class="option-examples">
<h4>Code examples</h4>
<dl class="option-examples-list">
<dt>
Initialize a button with the <code>text</code> option specified.
</dt>
<dd>
<pre><code>$( ".selector" ).button({ text: false });</code></pre>
</dd>
<dt>
Get or set the <code>text</code> option, after init.
</dt>
<dd>
<pre><code>//getter
var text = $( ".selector" ).button( "option", "text" );
//setter
$( ".selector" ).button( "option", "text", false );</code></pre>
</dd>
</dl>
</div>
</li>
<li class="option" id="option-icons">
<div class="option-header">
<h3 class="option-name"><a href="#option-icons">icons</a></h3>
<dl>
<dt class="option-type-label">Type:</dt>
<dd class="option-type">Options</dd>
<dt class="option-default-label">Default:</dt>
<dd class="option-default">{ primary: null, secondary: null }</dd>
</dl>
</div>
<div class="option-description">
<p>Icons to display, with or without text (see text option). The primary icon is displayed by default on the left of the label text, the secondary by default is on the right. Value for the primary and secondary properties must be a classname (String), eg. "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'}</p>
</div>
<div class="option-examples">
<h4>Code examples</h4>
<dl class="option-examples-list">
<dt>
Initialize a button with the <code>icons</code> option specified.
</dt>
<dd>
<pre><code>$( ".selector" ).button({ icons: {primary:'ui-icon-gear',secondary:'ui-icon-triangle-1-s'} });</code></pre>
</dd>
<dt>
Get or set the <code>icons</code> option, after init.
</dt>
<dd>
<pre><code>//getter
var icons = $( ".selector" ).button( "option", "icons" );
//setter
$( ".selector" ).button( "option", "icons", {primary:'ui-icon-gear',secondary:'ui-icon-triangle-1-s'} );</code></pre>
</dd>
</dl>
</div>
</li>
<li class="option" id="option-label">
<div class="option-header">
<h3 class="option-name"><a href="#option-label">label</a></h3>
<dl>
<dt class="option-type-label">Type:</dt>
<dd class="option-type">String</dd>
<dt class="option-default-label">Default:</dt>
<dd class="option-default">HTML content of the button, or value attribute</dd>
</dl>
</div>
<div class="option-description">
<p>Text to show on the button. When not specified (null), the element's html content is used, or its value attribute when it's an input element of type submit or reset; or the html content of the associated label element if its an input of type radio or checkbox</p>
</div>
<div class="option-examples">
<h4>Code examples</h4>
<dl class="option-examples-list">
<dt>
Initialize a button with the <code>label</code> option specified.
</dt>
<dd>
<pre><code>$( ".selector" ).button({ label: "custom label" });</code></pre>
</dd>
<dt>
Get or set the <code>label</code> option, after init.
</dt>
<dd>
<pre><code>//getter
var label = $( ".selector" ).button( "option", "label" );
//setter
</p>
$( ".selector" ).button( "option", "label", "custom label" );</code></pre>
</dd>
</dl>
</div>
</li>
</ul>
</div>
<div id="events">
<h2 class="top-header">Events</h2>
<ul class="events-list">
<p>There are no events for this plugin.</p>
</ul>
</div>
<div id="methods">
<h2 class="top-header">Methods</h2>
<ul class="methods-list">
<li class="method" id="method-destroy">
<div class="method-header">
<h3 class="method-name"><a href="#method-destroy">destroy</a></h3>
<dl>
<dt class="method-signature-label">Signature:</dt>
<dd class="method-signature">.button( "destroy"
)</dd>
</dl>
</div>
<div class="method-description">
<p>Remove the button functionality completely. This will return the element back to its pre-init state.</p>
</div>
</li>
<p>
<li class="method" id="method-disable">
<div class="method-header">
<h3 class="method-name"><a href="#method-disable">disable</a></h3>
<dl>
<dt class="method-signature-label">Signature:</dt>
<dd class="method-signature">.button( "disable"
)</dd>
</dl>
</div>
<div class="method-description">
<p>Disable the button.</p>
</div>
</li>
<li class="method" id="method-enable">
<div class="method-header">
<h3 class="method-name"><a href="#method-enable">enable</a></h3>
<dl>
<dt class="method-signature-label">Signature:</dt>
<dd class="method-signature">.button( "enable"
)</dd>
</dl>
</div>
<div class="method-description">
<p>Enable the button.</p>
</div>
</li>
<li class="method" id="method-option">
<div class="method-header">
<h3 class="method-name"><a href="#method-option">option</a></h3>
<dl>
<dt class="method-signature-label">Signature:</dt>
<dd class="method-signature">.button( "option"
, optionName
, <span class="optional">[</span>value<span class="optional">] </span>
)</dd>
</dl>
</div>
<div class="method-description">
<p>Get or set any button option. If no value is specified, will act as a getter.</p>
</div>
</li>
<li class="method" id="method-option">
<div class="method-header">
<h3 class="method-name"><a href="#method-option">option</a></h3>
<dl>
<dt class="method-signature-label">Signature:</dt>
<dd class="method-signature">.button( "option"
, options
)</dd>
</dl>
</div>
<div class="method-description">
<p>Set multiple button options at once by providing an options object.</p>
</div>
</li>
<li class="method" id="method-widget">
<div class="method-header">
<h3 class="method-name"><a href="#method-widget">widget</a></h3>
<dl>
<dt class="method-signature-label">Signature:</dt>
<dd class="method-signature">.button( "widget"
)</dd>
</dl>
</div>
<div class="method-description">
<p>Returns the .ui-button element.</p>
</div>
</li>
<li class="method" id="method-refresh">
<div class="method-header">
<h3 class="method-name"><a href="#method-refresh">refresh</a></h3>
<dl>
<dt class="method-signature-label">Signature:</dt>
<dd class="method-signature">.button( "refresh"
)</dd>
</dl>
</div>
<div class="method-description">
<p>Refreshes the visual state of the button. Useful for updating button state after the native element's checked or disabled state is changed programatically.</p>
</div>
</li>
</ul>
</div>
<div id="theming">
<h2 class="top-header">Theming</h2>
<p>The jQuery UI Button plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures. We recommend using the ThemeRoller tool to create and download custom themes that are easy to build and maintain.
</p>
<p>If a deeper level of customization is needed, there are widget-specific classes referenced within the jquery.ui.button.css stylesheet that can be modified. These classes are highlighed in bold below.
</p>
<h3>Sample markup with jQuery UI CSS Framework classes</h3>
<button class="<strong>ui-button ui-button-text-only</strong> ui-widget ui-state-default ui-corner-all"><br />
<span class="<strong>ui-button-text</strong>">Button Label</span><br /></button>
<p class="theme-note">
<strong>
Note: This is a sample of markup generated by the button plugin, not markup you should use to create a button. The only markup needed for that is <button>Button Label</button>.
</strong>
</p>
</div>
</div>
</p><!--
Pre-expand include size: 23021 bytes
Post-expand include size: 29105 bytes
Template argument size: 13482 bytes
Maximum: 2097152 bytes
-->
<!-- Saved in parser cache with key jqdocs_docs:pcache:idhash:3767-1!1!0!!en!2 and timestamp 20100909204132 -->