# All files / src/utils get-attribute.js

90% Statements 9/10
77.78% Branches 7/9
100% Functions 1/1
90% Lines 9/10

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27

    17x
    116x
    116x
    26x
    26x
    26x
    83x
    83x

    116x

     /**
     * 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++) {
          Eif (attr[i] !== undefined) {
            Iif(attr[i].nodeName === attr) {
              result = attr[i].nodeValue;
            }
          }
        }
      }
      return result;
    };