diff --git a/spec/domeSpec.js b/spec/domeSpec.js index 6edda0d..758e822 100644 --- a/spec/domeSpec.js +++ b/spec/domeSpec.js @@ -129,6 +129,35 @@ describe("dome", function () { }); }); + describe("addStyle", function () { + beforeEach(function () { + this.d = dome.get(".two"); + }); + afterEach(function () { + this.d.forEach(function (el) { + el.style.removeProperty('color'); + el.style.removeProperty('padding-top'); + }); + }); + it("can set inline element styles", function () { + this.d.addStyle({"color":"rgb(255, 0, 0)","padding-top":"5px"}); + expect(this.d[0].style.getPropertyValue("color")).toEqual("rgb(255, 0, 0)"); + expect(this.d[0].style.getPropertyValue("padding-top")).toEqual("5px"); + }); + }); + + describe("removeStyle", function () { + beforeEach(function () { + this.d = dome.get(".two"); + this.d.addStyle({"color":"rgb(255, 0, 0)","padding-top":"5px"}); + }); + it("can remove inline element styles", function () { + this.d.removeStyle(['color','padding-top']); + expect(this.d[0].style.getPropertyValue("color")).toEqual(null); + expect(this.d[0].style.getPropertyValue("padding-top")).toEqual(null); + }); + }); + describe("create", function () { it("can create elements", function () { expect(dome.create("p")[0].tagName).toEqual("P"); diff --git a/src/dome.js b/src/dome.js index 397f38d..692d6e6 100644 --- a/src/dome.js +++ b/src/dome.js @@ -95,6 +95,28 @@ window.dome = (function () { } }; + Dome.prototype.addStyle = function (val) { + return this.forEach(function(el) { + for (var prop in val) { + el.style[prop] = val[prop]; + } + }); + }; + + Dome.prototype.removeStyle = function (val) { + if(typeof val !== 'string') { + return this.forEach(function(el) { + for (var i = 0; i < val.length; i++) { + el.style.removeProperty(val[i]); + } + }); + } else { + return this.forEach(function(el) { + el.style.removeProperty(val); + }); + } + }; + Dome.prototype.append = function (els) { return this.forEach(function (parEl, i) { els.forEach(function (childEl) {