lib/air/attr.js
function attr(key, val) {
  var i, attrs, map = {};
  if(!this.length || key !== undefined && !Boolean(key)) {
    return this;
  }

  if(key === undefined && val === undefined) {
    // no args, get all attributes for first element as object
    attrs = this.dom[0].attributes;
    // convert NamedNodeMap to plain object
    for(i = 0;i < attrs.length;i++) {
      // NOTE: nodeValue is deprecated, check support for `value` in IE9!
      map[attrs[i].name] = attrs[i].value;
    }
    return map;
  }else if(typeof key === 'string' && !val) {
    // delete attribute on all matched elements
    if(val === null) {
      this.each(function(el) {
        el.removeAttribute(key);
      })
      return this;
    }
    // get attribute for first matched elements
    return this.dom[0].getAttribute(key);
  // handle object map of attributes
  }else {
    this.each(function(el) {
      if(typeof key === 'object') {
        for(var z in key) {
          if(key[z] === null) {
            el.removeAttribute(z);
            continue;
          }
          el.setAttribute(z, key[z]);
        }
      }else{
        el.setAttribute(key, val);
      }
    });
  }
  return this;
}
function attr(key, val) {
  var i, attrs, map = {};
  if(!this.length || key !== undefined && !Boolean(key)) {
    return this;
  }

  if(key === undefined && val === undefined) {
    // no args, get all attributes for first element as object
    attrs = this.dom[0].attributes;
    // convert NamedNodeMap to plain object
    for(i = 0;i < attrs.length;i++) {
      // NOTE: nodeValue is deprecated, check support for `value` in IE9!
      map[attrs[i].name] = attrs[i].value;
    }
    return map;
  }else if(typeof key === 'string' && !val) {
    // delete attribute on all matched elements
    if(val === null) {
      this.each(function(el) {
        el.removeAttribute(key);
      })
      return this;
    }
    // get attribute for first matched elements
    return this.dom[0].getAttribute(key);
  // handle object map of attributes
  }else {
    this.each(function(el) {
      if(typeof key === 'object') {
        for(var z in key) {
          if(key[z] === null) {
            el.removeAttribute(z);
            continue;
          }
          el.setAttribute(z, key[z]);
        }
      }else{
        el.setAttribute(key, val);
      }
    });
  }
  return this;
}
function attr ( key , val ) { var i , attrs , map = { } ; if ( ! this . length || key !== undefined && ! Boolean ( key ) ) { return this ; } if ( key === undefined && val === undefined ) { // no args, get all attributes for first element as object attrs = this . dom [ 0 ] . attributes ; // convert NamedNodeMap to plain object for ( i = 0 ; i < attrs . length ; i ++ ) { // NOTE: nodeValue is deprecated, check support for `value` in IE9! map [ attrs [ i ] . name ] = attrs [ i ] . value ; } return map ; } else if ( typeof key === 'string' && ! val ) { // delete attribute on all matched elements if ( val === null ) { this . each ( function ( el ) { el . removeAttribute ( key ) ; } ) return this ; } // get attribute for first matched elements return this . dom [ 0 ] . getAttribute ( key ) ; // handle object map of attributes } else { this . each ( function ( el ) { if ( typeof key === 'object' ) { for ( var z in key ) { if ( key [ z ] === null ) { el . removeAttribute ( z ) ; continue ; } el . setAttribute ( z , key [ z ] ) ; } } else { el . setAttribute ( key , val ) ; } } ) ; } return this ; }
Get the value of an attribute for the first element in the set of
matched elements or set one or more attributes for every matched element.
Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element .