0.1.0 • Published 9 years ago
resolve-id-refs v0.1.0
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
idsargument must be a string. Any other types will raise an error. - The second (optional) argument,
document, should be a Document or DocumentFragment instance. BecauseDocumentFragmentdoes 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-refsThen, require it in your bundle:
var resolve = require('resolve-id-refs');See the tests for more examples of usage.
0.1.0
9 years ago