o-dom Build Status

Origami DOM manipulation & traversal helpers.

Usage

JavaScript

getClosestMatch

Get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.

Arguments

  • el < DOMElement > The DOM element to start from.
  • selector < String > The CSS selector to match.

Returns

< DOMElement > or false

Example:

var dom = require('o-dom');
var closestListItem = dom.getClosestMatch(document.querySelector('li a'), 'li');

getIndex

Get the index of an element.

Arguments

  • el < DOMElement > The DOM element whose index to get.

Returns

< Number >

Example, assuming this HTML structure:

<ul>
    <li></li>
    <li id="target"></li>
    <li></li>
</ul>

dom.getIndex(document.getElementById('target')); would return 1.

Contributing

This module is suitable for helper functions that provide a convenient means of performing commonly required generic manipulation or selection of DOM elements. It should not be extended to contain:

  • Selector functions where querySelector would suffice
  • Anything event related
  • Polyfills (use browserFeatures in origami.json for that)
  • Anything that is has a good chance of being specific to a single component use case

Contact

If you have any questions or comments about this component, or need help using it, please either raise an issue, visit #ft-origami or email Origami Support.


Licence

This software is published by the Financial Times under the MIT licence.