1.0.0 • Published 10 years ago
findup-attribute v1.0.0
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
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.
1.0.0
10 years ago