-
Notifications
You must be signed in to change notification settings - Fork 21
get()
Karl edited this page Nov 13, 2017
·
7 revisions
Returns an item reference.
The method accepts a single argument in the following forms:
-
HTMLElement
- the element node. -
Number
- the index of the selectable element node. -
Array
- an array of element node or indexes. You may also pass instances ofHTMLCollection
orNodeList
.
The method returns an Object
or an Array
of objects of the following format:
{
node: HTMLElement, // the element node
rect: DOMRect, // the element node's bounding rects
startselected: Boolean // item was already selected on mousedown / touchstart
selected: Boolean, // item is currently selected
selecting: Boolean, // item is currently being selected
unselecting: Boolean // item is currently being deselected
}
<ul>
<li class="item ui-selected"></li>
<li class="item ui-selected"></li>
<li class="item ui-selected"></li>
<li class="item ui-selected"></li>
...
</ul>
const selectable = new Selectable({
filter: ".item"
});
// get the second item
const item = document.getElementsByClassName("item")[1];
selectable.get(item);
// or all of them
const items = document.querySelectorAll(".item");
selectable.get(items);