Skip to content

Conversation

@CharlotteGore
Copy link

Changes:

  • attributes can now be set (and unset) with an object of key value pairs
  • added tests (passing)
  • updated docs

@CharlotteGore
Copy link
Author

Not entirely sure I should be doing all this as one single pull request. Happy to break this apart if needed :)

@CharlotteGore
Copy link
Author

Added some spaces to the for and ifs, removed version number change.

@ianstormtaylor
Copy link
Contributor

good idea! i'd probably do it with the object check as the very first thing to exit early. also no need for the arguments length or own property checks with for the object i think

List.prototype.attr = function(name, val){

  // object
  if ('object' == typeof name) {
    for (var attr in obj) this.attr(attr, name[attr]);
    return this;
  }

  // get
  if (1 == arguments.length) {
    return this.els[0] && this.els[0].getAttribute(name);
  }

  // remove
  if (null == val) {
    return this.removeAttr(name);
  }

  // set
  return this.forEach(function(el){
    el.setAttribute(name, val);
  });
};

also single quotes ', double equals ==, and spaces after if braces ) {

@yields
Copy link
Member

yields commented Oct 20, 2013

also single quotes ', double equals ==, and spaces after if braces ) {

+1

@ianstormtaylor
Copy link
Contributor

lgtm :)

@marcelklehr
Copy link

+1

@matthewmueller
Copy link
Member

please rebase and we'll merge :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants