diff --git a/dist/tinydom.js b/dist/tinydom.js
index 84bb18ec51bb3714a1122649cc885cf36d38b148..fadfe9078db5a9e1e23268cb34610eb448f6b1f6 100644
--- a/dist/tinydom.js
+++ b/dist/tinydom.js
@@ -144,15 +144,16 @@ tinyDOM.fn = TinyDOMFunction.prototype = {
         }
     },
     attr: function (key, value) {
-        if (typeof (value) !== 'undefined') {
-            this.each(function(i, e){
-                e.setAttribute(key, value);
-            });
+        if (value === null) {
+			this.each(function(i, e){
+				e.removeAttribute(key);
+			});
             return this;
-        } else if (value === null) {
-            this.each(function(i, e){
-                e.removeAttribute(key);
+        } else if (typeof (value) !== 'undefined') {
+			this.each(function(i, e){
+				e.setAttribute(key, value);
 			});
+			return this;
 		} else {
             return this[0].getAttribute(key);
         }
diff --git a/dist/tinydom.min.js b/dist/tinydom.min.js
index 997fdd96162cee3392dc1be9b886ca8a5abef4d4..9cfa2529241d1b9f84093a4db4fc971f5fe4f153 100644
--- a/dist/tinydom.min.js
+++ b/dist/tinydom.min.js
@@ -1,2 +1,2 @@
 /*! tinydom 2018-03-15 */
-!function(){"use strict";if(Element&&!Element.prototype.matches){var a=Element.prototype;a.matches=a.matchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector||a.webkitMatchesSelector}var b,c;b=function(a){var c,d,e;if(!(this instanceof b))return new b(a);if(null===a||void 0===a)this.length=0;else if(a.substring)for(c=document.querySelectorAll(a),this.length=c.length,d=0;d<c.length;d++)e=c.item(d),this[d]=e;else if(a.push){for(d=0;d<a.length;d++)e=a[d],this[d]=e;this.length=a.length}else this[0]=a,this.length=1;return this.apiversion="1",this},c=function(a){return new b(a)},window.μ||(window.μ=c),window.mu||(window.mu=c),c.fn=b.prototype={each:function(a){for(var b=this.length;b--;)a(b,this[b],this);return this},on:function(a,b,c){return"string"==typeof b?this.each(function(d,e){e.addEventListener(a,function(a){var d=a.target,f=!1;do{d&&d.matches(b)?(c.call(d,a),f=!0):(d=d.parentNode)&&d.matches&&d!==e||(f=!0)}while(!0!==f)})}):(c=b,this.each(function(b,d){d.addEventListener(a,c)})),this},first:function(){return void 0!==this[0]?c(this[0]):null},parent:function(a){var b=this[0].parentNode,d=!0;if(c.exists(a)){for(;null!==b&&b!==document;){if(b.matches(a)){d=!1;break}b=b.parentNode}b=d?null:b}return c(b)},children:function(a){var b,d=this[0].childNodes,e=[];for(b=0;b<d.length;b++)c.isElement(d[b])&&(mu.exists(a)?d[b].matches(a)&&e.push(d[b]):e.push(d[b]));return c(e)},data:function(a,b){return void 0!==b?(this.each(function(c,d){d.setAttribute("data-"+a,b)}),this):this[0].getAttribute("data-"+a)},attr:function(a,b){return void 0!==b?(this.each(function(c,d){d.setAttribute(a,b)}),this):null!==b?this[0].getAttribute(a):void this.each(function(b,c){c.removeAttribute(a)})},class:function(a,b){return c.exists(b)?this.each(function(c,d){d.classList.toggle(a,b)}):this.each(function(b,c){c.classList.toggle(a)}),this},clear:function(){this.each(function(a,b){for(;b.firstChild;)b.removeChild(b.firstChild)})},trigger:function(a,b,d,e){d=!c.exists(d)||d,e=!c.exists(e)||e;var f=new CustomEvent(a,b,d,e);return this.each(function(a,b){b.dispatchEvent(f)}),this}},c.ready=function(a){document.addEventListener("DOMContentLoaded",a)},c.isElement=function(a){var b=!1;try{b=a instanceof HTMLElement}catch(c){b=a.nodeType&&1===a.nodeType}return b},c.exists=function(a){return null!==a&&void 0!==a},c.byID=function(a){return c(document.getElementById(a))},c.triggerOn=function(a,b,d,e,f){e=!c.exists(e)||e,f=!c.exists(f)||f,a.dispatchEvent(new CustomEvent(b,d,e,f))},c.json={keys:function(a){var b,c=[];for(b in a)a.hasOwnProperty(b)&&c.push(b);return c},is:function(a){try{return JSON.parse(a),null!==a&&void 0!==a}catch(b){return!1}},merge:function(a,b){if(c.exists(a)){if(c.exists(b)){var d;for(d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);return a}return a}return b}},c.ajax=function(a){var b,d,e=new XMLHttpRequest,f={method:"GET",url:"",async:!0,user:null,password:null,responseType:"text",data:null,headers:[],callbacks:{}},g=function(a){return function(b){a(b.currentTarget.response,b)}};if(c.json.merge(f,a),e.responseType=f.responseType,this.exists(f.callbacks))for(b in f.callbacks)f.callbacks.hasOwnProperty(b)&&e.addEventListener(b,g(f.callbacks[b]));for(e.open(f.method,f.url,f.async,f.user,f.password),d=0;d<f.headers.length;d++)e.setRequestHeader(f.headers[d].header,f.headers[d].value);return e.send(f.data),e}}();
\ No newline at end of file
+!function(){"use strict";if(Element&&!Element.prototype.matches){var a=Element.prototype;a.matches=a.matchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector||a.webkitMatchesSelector}var b,c;b=function(a){var c,d,e;if(!(this instanceof b))return new b(a);if(null===a||void 0===a)this.length=0;else if(a.substring)for(c=document.querySelectorAll(a),this.length=c.length,d=0;d<c.length;d++)e=c.item(d),this[d]=e;else if(a.push){for(d=0;d<a.length;d++)e=a[d],this[d]=e;this.length=a.length}else this[0]=a,this.length=1;return this.apiversion="1",this},c=function(a){return new b(a)},window.μ||(window.μ=c),window.mu||(window.mu=c),c.fn=b.prototype={each:function(a){for(var b=this.length;b--;)a(b,this[b],this);return this},on:function(a,b,c){return"string"==typeof b?this.each(function(d,e){e.addEventListener(a,function(a){var d=a.target,f=!1;do{d&&d.matches(b)?(c.call(d,a),f=!0):(d=d.parentNode)&&d.matches&&d!==e||(f=!0)}while(!0!==f)})}):(c=b,this.each(function(b,d){d.addEventListener(a,c)})),this},first:function(){return void 0!==this[0]?c(this[0]):null},parent:function(a){var b=this[0].parentNode,d=!0;if(c.exists(a)){for(;null!==b&&b!==document;){if(b.matches(a)){d=!1;break}b=b.parentNode}b=d?null:b}return c(b)},children:function(a){var b,d=this[0].childNodes,e=[];for(b=0;b<d.length;b++)c.isElement(d[b])&&(mu.exists(a)?d[b].matches(a)&&e.push(d[b]):e.push(d[b]));return c(e)},data:function(a,b){return void 0!==b?(this.each(function(c,d){d.setAttribute("data-"+a,b)}),this):this[0].getAttribute("data-"+a)},attr:function(a,b){return null===b?(this.each(function(b,c){c.removeAttribute(a)}),this):void 0!==b?(this.each(function(c,d){d.setAttribute(a,b)}),this):this[0].getAttribute(a)},class:function(a,b){return c.exists(b)?this.each(function(c,d){d.classList.toggle(a,b)}):this.each(function(b,c){c.classList.toggle(a)}),this},clear:function(){this.each(function(a,b){for(;b.firstChild;)b.removeChild(b.firstChild)})},trigger:function(a,b,d,e){d=!c.exists(d)||d,e=!c.exists(e)||e;var f=new CustomEvent(a,b,d,e);return this.each(function(a,b){b.dispatchEvent(f)}),this}},c.ready=function(a){document.addEventListener("DOMContentLoaded",a)},c.isElement=function(a){var b=!1;try{b=a instanceof HTMLElement}catch(c){b=a.nodeType&&1===a.nodeType}return b},c.exists=function(a){return null!==a&&void 0!==a},c.byID=function(a){return c(document.getElementById(a))},c.triggerOn=function(a,b,d,e,f){e=!c.exists(e)||e,f=!c.exists(f)||f,a.dispatchEvent(new CustomEvent(b,d,e,f))},c.json={keys:function(a){var b,c=[];for(b in a)a.hasOwnProperty(b)&&c.push(b);return c},is:function(a){try{return JSON.parse(a),null!==a&&void 0!==a}catch(b){return!1}},merge:function(a,b){if(c.exists(a)){if(c.exists(b)){var d;for(d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);return a}return a}return b}},c.ajax=function(a){var b,d,e=new XMLHttpRequest,f={method:"GET",url:"",async:!0,user:null,password:null,responseType:"text",data:null,headers:[],callbacks:{}},g=function(a){return function(b){a(b.currentTarget.response,b)}};if(c.json.merge(f,a),e.responseType=f.responseType,this.exists(f.callbacks))for(b in f.callbacks)f.callbacks.hasOwnProperty(b)&&e.addEventListener(b,g(f.callbacks[b]));for(e.open(f.method,f.url,f.async,f.user,f.password),d=0;d<f.headers.length;d++)e.setRequestHeader(f.headers[d].header,f.headers[d].value);return e.send(f.data),e}}();
\ No newline at end of file
diff --git a/src/Batch.js b/src/Batch.js
index 72c28847ad6e91a39dcaf66b4215f79d1449d128..e5858173d9d94bd96392a332e45214d859787d0f 100644
--- a/src/Batch.js
+++ b/src/Batch.js
@@ -84,15 +84,16 @@ tinyDOM.fn = TinyDOMFunction.prototype = {
         }
     },
     attr: function (key, value) {
-        if (typeof (value) !== 'undefined') {
-            this.each(function(i, e){
-                e.setAttribute(key, value);
-            });
+        if (value === null) {
+			this.each(function(i, e){
+				e.removeAttribute(key);
+			});
             return this;
-        } else if (value === null) {
-            this.each(function(i, e){
-                e.removeAttribute(key);
+        } else if (typeof (value) !== 'undefined') {
+			this.each(function(i, e){
+				e.setAttribute(key, value);
 			});
+			return this;
 		} else {
             return this[0].getAttribute(key);
         }