dom
dom copied to clipboard
Add support for setting attributes with an object
Changes:
- attributes can now be set (and unset) with an object of key value pairs
- added tests (passing)
- updated docs
Not entirely sure I should be doing all this as one single pull request. Happy to break this apart if needed :)
Added some spaces to the for and ifs, removed version number change.
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 ) {
also single quotes ', double equals ==, and spaces after if braces ) {
+1
lgtm :)
+1
please rebase and we'll merge :-)