Skip to content

Commit db3fce7

Browse files
authored
fix(prop): Update attribute value when setting prop (#1579)
Fixes #883 Fixes #927 Fixes #1364
1 parent c58258f commit db3fce7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/api/attributes.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ var getProp = function (el, name) {
120120
};
121121

122122
var setProp = function (el, name, value) {
123-
el[name] = rboolean.test(name) ? !!value : value;
123+
if (name in el) {
124+
el[name] = value;
125+
} else {
126+
setAttr(el, name, rboolean.test(name) ? (value ? '' : null) : value);
127+
}
124128
};
125129

126130
/**

test/api/attributes.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ describe('$(...)', function () {
172172
expect(checkbox.prop('checked')).to.equal(true);
173173
});
174174

175+
it('(key, value) : should update attribute', function () {
176+
expect(checkbox.prop('checked')).to.equal(true);
177+
expect(checkbox.attr('checked')).to.equal('checked');
178+
checkbox.prop('checked', false);
179+
expect(checkbox.prop('checked')).to.equal(false);
180+
expect(checkbox.attr('checked')).to.equal(undefined);
181+
checkbox.prop('checked', true);
182+
expect(checkbox.prop('checked')).to.equal(true);
183+
expect(checkbox.attr('checked')).to.equal('checked');
184+
});
185+
175186
it('(map) : object map should set multiple props', function () {
176187
checkbox.prop({
177188
id: 'check',

0 commit comments

Comments
 (0)