Björn f184cd7e2a | 4 years ago | |
---|---|---|
.. | ||
LICENSE | 4 years ago | |
README.md | 4 years ago | |
index.js | 4 years ago | |
index.next.js | 4 years ago | |
package.json | 4 years ago |
import domToArray from 'bianco.dom-to-array'
var div = document.createElement('div')
div.innerHTML = `
<ul>
<li>one</li>
<li>two</li>
</ul>
`
body.appendChild(div)
// It can convert node list
const lis = document.querySelectorAll('li')
const $lis = domToArray(lis)
$lis.length // => 2
Array.isArray($lis) // => true
// It can convert a single node
const li = document.querySelector('li')
const $li = domToArray(li)
$li.length // => 1
Array.isArray($li) // => true
Converts any DOM node/s to a loopable array
Parameters
els
(HTMLElement | NodeList) single html element or a node listReturns Array always a loopable object