Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.25 KB

README.md

File metadata and controls

48 lines (33 loc) · 1.25 KB

q

A tiny library to be used with browserify that gives arrays rather than NodeLists from DOM queries.

Installation

$ npm install @artcommacode/q --save

Usage

q wraps querySelector and querySelectorAll in one function. It returns arrays rather than NodeLists except when there is a single element in which case it returns the element itself.

var q = require('@artcommacode/q')

q('ul li')
// => [ <li>...</li>, <li>...</li>, <li>...</li> ]

q('ul li')[0].textContent
// => $1

q('ul li')[0] === q('ul li:first-of-type')
// => true

Pass an element in as the second argument to run a query on it:

var ul = q('ul')
q('li', ul)
// => [ <li>...</li>, <li>...</li>, <li>...</li> ]

q will return an empty array if no elements are found:

q('ul div')
// => []

Tests

$ npm install && npm test

This will open a tab in your browser to run tests against test/index.html with the results displayed in your terminal. If you see # ok then it all went well, if there's any errors please submit an issue.