You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.7 KiB

5 years ago
  1. # bianco.dom-to-array
  2. [![Build Status][travis-image]][travis-url]
  3. [![NPM version][npm-version-image]][npm-url]
  4. [![NPM downloads][npm-downloads-image]][npm-url]
  5. [![MIT License][license-image]][license-url]
  6. ## Usage
  7. ```js
  8. import domToArray from 'bianco.dom-to-array'
  9. var div = document.createElement('div')
  10. div.innerHTML = `
  11. <ul>
  12. <li>one</li>
  13. <li>two</li>
  14. </ul>
  15. `
  16. body.appendChild(div)
  17. // It can convert node list
  18. const lis = document.querySelectorAll('li')
  19. const $lis = domToArray(lis)
  20. $lis.length // => 2
  21. Array.isArray($lis) // => true
  22. // It can convert a single node
  23. const li = document.querySelector('li')
  24. const $li = domToArray(li)
  25. $li.length // => 1
  26. Array.isArray($li) // => true
  27. ```
  28. [travis-image]: https://img.shields.io/travis/biancojs/dom-to-array.svg?style=flat-square
  29. [travis-url]: https://travis-ci.org/biancojs/dom-to-array
  30. [license-image]: http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
  31. [license-url]: LICENSE.txt
  32. [npm-version-image]: http://img.shields.io/npm/v/bianco.dom-to-array.svg?style=flat-square
  33. [npm-downloads-image]: http://img.shields.io/npm/dm/bianco.dom-to-array.svg?style=flat-square
  34. [npm-url]: https://npmjs.org/package/bianco.dom-to-array
  35. ## API
  36. <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
  37. ### domToArray
  38. Converts any DOM node/s to a loopable array
  39. **Parameters**
  40. - `els` **([HTMLElement](https://developer.mozilla.org/en-US/docs/Web/HTML/Element) \| [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList))** single html element or a node list
  41. Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** always a loopable object