This repository was archived by the owner on Jul 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
select()
Karl edited this page Nov 4, 2017
·
18 revisions
Selects an item.
The method accepts a single argument in the follwing forms:
-
HTMLElement- the selectable element you want to select. -
Number- the index of the selectable element (not it's index in theparentNode). -
Object- a reference to theitemstored in theitemsarray. -
Array- an array of nodes, indexes or objects. You may also pass instances ofHTMLCollectionorNodeList.
// as a node
var item = document.querySelectorAll("li")[1];
selectable.select(item);
// as an index
selectable.select(1);
// as a reference to the item
var item = selectable.items[1];
selectable.select(item);If selecting an item via an index, you must pass the index as the node would appear in the collection of selectable items, not the node's position relative to it's parent nodes children.
<ul>
<li class="ul-selectable"><li> // index 0
<li><li>
<li><li>
<li class="ul-selectable"><li> // index 1
<li class="ul-selectable"><li> // index 2
<li class="ul-selectable"><li> // index 3
<li><li>
<li class="ul-selectable"><li> // index 4
</ul>
### Select the first and second items
```javascript
// incorrect
selectable.select([0,3]);
// correct
selectable.select([0,1]);