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');
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. Because DocumentFragment
does not provide a
getElementById()
method, we use querySelector('[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.