dom icon indicating copy to clipboard operation
dom copied to clipboard

Add support for setting attributes with an object

Open CharlotteGore opened this issue 12 years ago • 7 comments

Changes:

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

CharlotteGore avatar Oct 20 '13 12:10 CharlotteGore

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

CharlotteGore avatar Oct 20 '13 12:10 CharlotteGore

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

CharlotteGore avatar Oct 20 '13 13:10 CharlotteGore

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 ) {

ianstormtaylor avatar Oct 20 '13 17:10 ianstormtaylor

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

+1

yields avatar Oct 20 '13 17:10 yields

lgtm :)

ianstormtaylor avatar Oct 23 '13 20:10 ianstormtaylor

+1

marcelklehr avatar Jan 18 '14 13:01 marcelklehr

please rebase and we'll merge :-)

matthewmueller avatar Jan 18 '14 13:01 matthewmueller