From db3fce736dbcbaf8f4f1aa2ee46a7550d6805d75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20B=C3=B6hm?= Date: Tue, 22 Dec 2020 19:14:00 +0100 Subject: [PATCH] fix(prop): Update attribute value when setting prop (#1579) Fixes #883 Fixes #927 Fixes #1364 --- lib/api/attributes.js | 6 +++++- test/api/attributes.js | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/api/attributes.js b/lib/api/attributes.js index 96e0795c66..ce2c78b15f 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 6ef8ce0f45..a6a3ababb1 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',