1.0.0 • Published 10 years ago

findup-attribute v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

findup-attribute

npm.io npm.io npm.io npm.io

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.