Skip to content

component/selectable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

selectable

Selectable DOM elements.

dom element selection js component

Installation

$ component install component/selectable

Example

<ul id="pets">
  <li data-name="tobi">Tobi</li>
  <li data-name="loki">Loki</li>
  <li data-name="jane">Jane</li>
  <li data-name="abby">Abby</li>
</ul>

<script>
  var selectable = require('selectable');
  var selection = selectable('#pets > li');

  selection.on('change', function(e){
    for (var i = 0; i < e.selected.length; i++) {
      console.log(e.selected[i].getAttribute('data-name'));
    }
  });
</script>

API

Selectable(selector, el)

Make elements with the given selector selectable, with optional context el.

Selectable#select(els)

Add the given els to the selection.

Selectable#deselect(els)

Remove the given els from the selection.

License

MIT