Given a child attribute, findup-attribute
will traverse its way up the DOM
until it finds and returns an element with the expected attribute.
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>
MIT. See LICENSE.md for details.