select()
Selects an item or a collection of items.
The method accepts a single argument in the following forms:
HTMLElementHTMLCollectionNodeListNumber- the index of the selectable item in theitemsarrayObject- a reference to theitemstored in theitemsarrayArray- an array ofHTMLElement, indexes or item references
Selecting single items
<ul id="list">
<li class="ul-selectable"></li>
<li class="ul-selectable"></li>
<li class="ul-selectable"></li>
<li class="ul-selectable"></li>
</ul>const list = document.getElementById('list');
const selectable = new Selectable({
container: list
});
// as a node
const item = list.querySelectorAll("li")[0];
selectable.select(item);
// as an index
const itemIndex = 0;
selectable.select(itemIndex);
// as a reference to the item
const item = selectable.items[0];
selectable.select(item);Selecting multiple items
Using indexes
Select the first, second and third items
Last updated