-
Notifications
You must be signed in to change notification settings - Fork 4
Element::items
Method for storing/removing items
$(element).items({arguments})
This method will execute different routines depending on the arguments passed.
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');
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');
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);
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);
Selecting an item by its index.
// Selecting the first child
$('#contacts').items(0);
// Selecting the last child
$('#contacts').items(-1);
Adding one or more items to items.
$('#contacts').items('add', {first:'Albert', last:'Einstein'}, ...);
Adding array of items.
$('#contacts').items('merge', [
{first:'Albert', last:'Einstein'},
{first:'Julius', last:'Caesar'}
]);
Replacing items with new items.
$('#contacts').items('replace', [
{first:'Albert', last:'Einstein'},
{first:'Julius', last:'Caesar'}
]);
Remove item
$('#contacts').items('remove', 0);
$('#contacts').items('remove', item2);
Like items() but returns array of data instead of the jQuery object.
Empty items.
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});
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
Returns its status. true if active.