resolve-id-refs
v0.1.0
Published
Resolve an ID reference list to an array of DOM elements
Downloads
159,677
Readme
resolve-id-refs
This module exports a function that resolves a HTML ID reference list into an array of elements. An ID reference list is a string in which one or more ids is separated by whitespace. Whitespace at the beginning and end of the string is trimmed, and any ID that is not found in the document raises an error.
var resolve = require('resolve-id-refs');
resolve('foo bar');
// => [
// document.getElementById('foo'),
// document.getElementById('bar')
// ]
API
resolve(ids<String> [, document<Document|DocumentFragment>]) => Array<Element>
- The
ids
argument must be a string. Any other types will raise an error. - The second (optional) argument,
document
, should be a Document or DocumentFragment instance. BecauseDocumentFragment
does not provide agetElementById()
method, we usequerySelector('[id="' + id + '"]')
.
Installation
This is a Node module intended for use with browser bundling tools, such as browserify and webpack. To install it in your project, run:
npm install --save resolve-id-refs
Then, require it in your bundle:
var resolve = require('resolve-id-refs');
See the tests for more examples of usage.