findup-attribute

1.0.0 • Public • Published

findup-attribute

Given a child attribute, findup-attribute will traverse its way up the DOM until it finds and returns an element with the expected attribute.

Usage

NPM

findup(child, nodeAttr)

Find the closest parent attribute with attribute nodeAttr.

For example, the following will pick up clicks on elements using a on-click attribute with only a single event listener:

var findupAttribute = require('findup-attribute')

document.body.addEventListener('click', function(e) {
  var li = findupAttribute(e.srcElement, 'on-click')
}, false)
<body>
  <ul>
    <li on-click="thing"><a href="#">click me</a></li>
    <li on-click="thing"><a href="#">click me</a></li>
    <li on-click="thing"><a href="#">click me</a></li>
    <li on-click="thing"><a href="#">click me</a></li>
  </ul>
</body>

License

MIT. See LICENSE.md for details.

Package Sidebar

Install

npm i findup-attribute

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • hughsk