A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://learn.jquery.com/jquery-ui/widget-factory/widget-method-invocation/ below:

Widget Method Invocation | jQuery Learning Center

Widgets created with the widget factory use methods to change their state and perform actions after initialization. There are two ways widget methods can be invoked - through the plugin created by the widget factory, or by invoking the method on the element's instance object.

link Plugin Invocation

To invoke a method using the widget's plugin, pass the name of the method as a string. For example, here is how you call the dialog widget's close() method.

1

$( ".selector" ).dialog( "close" );

If the method requires arguments, pass them as additional parameters to the plugin. Here is how you call dialog's option() method.

1

$( ".selector" ).dialog( "option", "height" );

This returns the value of the dialog's height option.

link Instance Invocation

Under the hoods, every instance of every widget is stored on the element using jQuery.data(). To retrieve the instance object, call jQuery.data() using the widget's full name as the key. This is shown below.

1

var dialog = $( ".selector" ).data( "ui-dialog" );

After you have a reference to the instance object, methods can be invoked on it directly.

1

2

var dialog = $( ".selector" ).data( "ui-dialog" );

In jQuery UI 1.11, the new instance() method will make this process even easier.

1

$( ".selector" ).dialog( "instance" ).close();

link Return Types

Most methods invoked through the widget's plugin will return a jQuery object so the method call can be chained with additional jQuery methods. This is even true of methods that return undefined when invoked on the instance. This is shown in the example below.

1

2

3

4

5

6

7

8

9

10

11

12

var dialog = $( ".selector" ).dialog();

dialog.data( "ui-dialog" ).close();

dialog.dialog( "close" );

The exception to this are methods that return information about the widget. For example dialog's isOpen() method.

This produces a TypeError error as isOpen() returns a boolean, not a jQuery object.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4