YUI recommends YUI3.
YUI 2 has been deprecated since 2011. This site acts as an archive for files and documentation.
This documentation is no longer maintained.
This example demonstrates different ways to create a Button that functions like an HTML <a/>
element.
A Link Button can be instantiated three different ways:
<a/>
elementA Link Button can be created using an existing <a/>
element as a source element, the attributes of which are captured and used for the creation of a new element that replaces the source element inline.
Pass the id of the source element as the first argument to the Button's constructor. Additional configuration attributes for a Button can be set at instantiation time by specifying them in an object literal that is passed as the second argument to the Button's constructor. Note: the value of configuration attributes passed to the Button constructor will trump those of the corresponding HTML attributes of the original source element.
A Link Button can also be instantiated using pre-defined Button Control HTML: An element with a class of "yui-button" and "yui-link-button" containing a element with a class of "first-child" containing an <a/>
element:
To instantiate a Link Button using the Button Control HTML, pass the id of the Button's root element (the element with the classes "yui-button" and "yui-link-button" applied) as the first argument to constructor and any additional configuration attributes as the second argument via an object literal.
To build a Link Button without any existing HTML, pass a set of configuration attributes as a single argument to the constructor using an object literal.
In most cases, it is necessary to specify the button's id, type, label and container (the HTML element that the button should be appended to once created). If an id is not specified for the button, one will be generated using the generateId
method of the Dom utility. Similarly, if the "type" attribute is omitted, the default type of "button" will be applied.
Note: Logging and debugging is currently turned off for this example.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.
Copyright © 2013 Yahoo! Inc. All rights reserved.