list.js
Version:
The perfect library for lists. Supports search, sort, filters and flexibility. Built to be invisible and work on existing HTML
27 lines (25 loc) • 645 B
JavaScript
/**
* A cross-browser implementation of getAttribute.
* Source found here: http://stackoverflow.com/a/3755343/361337 written by Vivin Paliath
*
* Return the value for `attr` at `element`.
*
* @param {Element} el
* @param {String} attr
* @api public
*/
module.exports = function (el, attr) {
var result = (el.getAttribute && el.getAttribute(attr)) || null
if (!result) {
var attrs = el.attributes
var length = attrs.length
for (var i = 0; i < length; i++) {
if (attrs[i] !== undefined) {
if (attrs[i].nodeName === attr) {
result = attrs[i].nodeValue
}
}
}
}
return result
}