Skip to content

Commit 1d2e8a7

Browse files
elias-winfb55
authored andcommittedJul 4, 2016
Return undefined in .prop if given an invalid element or tag (#880)
1 parent df55c93 commit 1d2e8a7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
 

‎lib/api/attributes.js

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ exports.attr = function(name, value) {
9191
};
9292

9393
var getProp = function (el, name) {
94+
if (!el || !isTag(el)) return;
95+
9496
return el.hasOwnProperty(name)
9597
? el[name]
9698
: rboolean.test(name)

‎test/api/attributes.js

+5
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ describe('$(...)', function() {
182182
it('(key, value) : should support chaining after setting props', function() {
183183
expect(checkbox.prop('checked', false)).to.equal(checkbox);
184184
});
185+
186+
it('(invalid element/tag) : prop should return undefined', function() {
187+
expect($(undefined).prop('prop')).to.be(undefined);
188+
expect($(null).prop('prop')).to.be(undefined);
189+
});
185190
});
186191

187192
describe('.data', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.