diff --git a/lib/api/attributes.js b/lib/api/attributes.js index be0b889b1a..9acaf929f4 100644 --- a/lib/api/attributes.js +++ b/lib/api/attributes.js @@ -120,7 +120,11 @@ var getProp = function (el, name) { }; var setProp = function (el, name, value) { - el[name] = rboolean.test(name) ? !!value : value; + if (name in el) { + el[name] = value; + } else { + setAttr(el, name, rboolean.test(name) ? (value ? '' : null) : value); + } }; /** diff --git a/test/api/attributes.js b/test/api/attributes.js index 6f338fe5f2..0b57869faf 100644 --- a/test/api/attributes.js +++ b/test/api/attributes.js @@ -172,6 +172,17 @@ describe('$(...)', function () { expect(checkbox.prop('checked')).to.equal(true); }); + it('(key, value) : should update attribute', function () { + expect(checkbox.prop('checked')).to.equal(true); + expect(checkbox.attr('checked')).to.equal('checked'); + checkbox.prop('checked', false); + expect(checkbox.prop('checked')).to.equal(false); + expect(checkbox.attr('checked')).to.equal(undefined); + checkbox.prop('checked', true); + expect(checkbox.prop('checked')).to.equal(true); + expect(checkbox.attr('checked')).to.equal('checked'); + }); + it('(map) : object map should set multiple props', function () { checkbox.prop({ id: 'check', @@ -211,6 +222,23 @@ describe('$(...)', function () { }); }); + it('modifying nested selections should not impact the parent', function () { + var apple = $('.apple'); + var pear = $('.pear'); + + var applePear = apple.add(pear); + + applePear.addClass('red'); + + expect(apple.hasClass('red')).to.be.ok(); + expect(pear.hasClass('red')).to.be.ok(); + + // applies green to pear... AND apple + pear.addClass('green'); + expect(pear.hasClass('green')).to.be.ok(); //currently this is true + expect(apple.hasClass('green')).to.be.ok(); // and this is true! + }); + describe('.data', function () { beforeEach(function () { $ = cheerio.load(chocolates);