Skip to content
raid-ox edited this page Sep 13, 2010 · 8 revisions

Method for storing/removing items

Syntax

$(element).items({arguments})

Routines

This method will execute different routines depending on the arguments passed.

items()

If no argument is passed, it will returns jQuery object containing all visible/filtered items.
This only works if items and chain is active. Otherwise it will return empty jQuery object.

$('#contacts').items().css('color': 'red');

items(true)

If true argument is passed. It will returns jQuery object containing all – including hidden/filtered out – items.
Same as above, it will only work if items and chain is active.

$('#contacts').items(true).css('color': 'blue');

items(object)

If you pass an object to items, it will get the item which have the same data as the object.

var data = {first:'Bill', last:'Gates'};
$('#contacts')
	.items([data, {first:'Linus', last:'Torvalds'}{first:'Steve', last:'Jobs'}])
	.chain();

var item = $('#contacts').items(data);

items(item)

It will return the item back if item is part of the element items. Otherwise it will return empty jQuery object.


var item1 = $('#contacts').items(0); var item2 = $('#posts').items(0);

// Returns item1
$(‘#contacts’).items(item1);

// Returns empty jQuery
$(‘#posts’).items(item1);


items(Number)

Selecting an item by its index.

// Selecting the first child
$('#contacts').items(0);

// Selecting the last child
$('#contacts').items(-1);

items('add')

Adding one or more items to items.

$('#contacts').items('add', {first:'Albert', last:'Einstein'}, ...);

items('merge')

Adding array of items.

$('#contacts').items('merge', [
	{first:'Albert', last:'Einstein'},
	{first:'Julius', last:'Caesar'}
]);

items('replace')

Replacing items with new items.

$('#contacts').items('replace', [
	{first:'Albert', last:'Einstein'},
	{first:'Julius', last:'Caesar'}
]);

items('remove')

Remove item

$('#contacts').items('remove', 0);
$('#contacts').items('remove', item2);

items('data')

Like items() but returns array of data instead of the jQuery object.

items('empty')

Empty items.

items('sort', property, options)

Sort items by property.

options

  • toggle:boolean – Automatic switch between ascending and descending
  • desc:boolean – Sort descending
  • type:string – type of data, accept ‘number’ and ‘default’
$('#contacts').items('sort', 'name', {desc: true, toggle: true});

items('filter', text, properties)

Filter items by criteria. Filtered items will be hidden.

$('#contacts').items('filter', 'Bill');
$('#contacts').items('filter', 'Bill', 'name');
$('#contacts').items('filter', 'Bill', ['name', 'address']);
$('#contacts').items('filter', null); // Turn off filter

items('active')

Returns its status. true if active.

Clone this wiki locally