Methods - daneWilliams/jquery.dropdown GitHub Wiki

Many dropdown methods can be called manually, allowing for fine-tuned control.


Dropdown

Open

$(element).dropdown( 'open' );

Close

$(element).dropdown( 'close' );

Resize

$(element).dropdown( 'resize' );

Update toggle text

$(element).dropdown( 'toggleText', text );

If multi is enabled, use the toggleTextMulti method instead. Providing text which has already been set will remove it.


Menus

Add

$(element).dropdown( 'addMenu', {
	id: null,		// HTML ID attribute
	uid: null,		// Unique ID for this menu
	parent: false,	// Parent item's unique ID
	items: null		// Array of item UIDs
});

Get

jQuery selector/object

$(element).dropdown( 'getMenu', '#menu-1' );
$(element).dropdown( 'getMenu', $('#menu-1') );

Unique ID

$(element).dropdown( 'getMenu', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' );

Open/Close

If true is passed as the second parameter, the menu will be opened instantly rather than animated.

Open

$(element).dropdown( 'openMenu', '#menu-1' );
$(element).dropdown( 'openMenu', '#menu-1', true );

Close

$(element).dropdown( 'closeMenu', '#menu-1' );
$(element).dropdown( 'closeMenu', '#menu-1', true );

Items

Add

$(element).dropdown( 'addItem', {
	id: null,			// HTML ID attribute
	uid: null,			// Unique ID for this item
	text: '',			// Text to display
	value: null,		// Item value
	url: null,			// URL
	html: null,			// HTML to display instead of text
	menu: false,		// Unique ID of the menu this item belongs to
	parent: false,		// Unique ID of this item's parent
	children: {
		menu:  false,	// Unique ID of the menu belonging to this item
		title: '',		// Title for this item's menu
		items: false	// Array of item UIDs
	},
	selected: false,	// Whether or not this item is selected
	selectable: true	// Whether or not this item can be selected
});

Get

jQuery selector/object

$(element).dropdown( 'getItem', '#item-1' );
$(element).dropdown( 'getItem', $('#item-1') );

Unique ID

$(element).dropdown( 'getItem', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' );

Check if item is selected

if ( $(element).dropdown( 'selected', item ) ) {

    ....

}
```

### Get selected item(s)

$(element).dropdown( 'selected' );


### Get item value

$(element).dropdown( 'value', item );


### Get current value

$(element).dropdown( 'value' );


### Get item text

$(element).dropdown( 'text', item );


### Select
#### Individual item

$(element).dropdown( 'select', item );

#### By value(s)
If `true` is passed as the second parameter, all currently selected items will be deselected.
```
$(element).dropdown( 'selectValue', 'value1' );
$(element).dropdown( 'selectValue', 'value1', true );
$(element).dropdown( 'selectValue', [ 'value1', 'value2' ] );
$(element).dropdown( 'selectValue', [ 'value1', 'value2' ], true );

Deselect

$(element).dropdown( 'deselect', '#item-1' );

Focus

$(element).dropdown( 'focus', '#item-1' );