back to Overview

.per()

Invokes the handler function for each list element with a single-element list containing only this element.
Util module only.

Syntax Variants

list.per(callback)
list.per(subSelector, callback)

Parameters

subSelector (optional)
a selector as valid as first argument for $(), to identify the descendants to iterate over.
callback
The callback function(itemList, index) to invoke for each list element.
item
The current list element wrapped in a Minfified list.
index
The second the zero-based index of the current element.
this
The list that is being iterated. If a sub-selector is being used, it is the list that resulted from using the sub-selector.
The callback's return value will be ignored.
(return value)
the list. Even if you specified a sub-selector, it will always return the original list.

Description

Invokes the handler function for each list element with a single-element list containing only this element. It is very similar to each(), but instead of giving the element itself it wraps the element in a Minified list. Additionally, you can specify a sub-selector to iterate over the descendants matches by the selector instead of the list elements.

Example

Create a mouseover toggle for a list:

$('.toggler').per(function(el, i) {
    el.onOver(el.toggle('myeffect'));
});

Example

Create click handlers for elements in a list:

$('#list').add(HTML('{{each}}<li>{{this.name}} <a class="del" href="#">Delete</a></li>{{each}}', items)
               .per('.del', function(el, index) {
                  el.on('click', deleteItemByName, [items[index].name]);
               }));

Comments

comments powered by Disqus

back to Overview

Functions