diff --git a/lib/api/attributes.js b/lib/api/attributes.js index a0fec61409..199abb59d9 100644 --- a/lib/api/attributes.js +++ b/lib/api/attributes.js @@ -91,6 +91,8 @@ exports.attr = function(name, value) { }; var getProp = function (el, name) { + if (!el || !isTag(el)) return; + return el.hasOwnProperty(name) ? el[name] : rboolean.test(name) diff --git a/test/api/attributes.js b/test/api/attributes.js index c23a1ff4b7..21f29e786d 100644 --- a/test/api/attributes.js +++ b/test/api/attributes.js @@ -182,6 +182,11 @@ describe('$(...)', function() { it('(key, value) : should support chaining after setting props', function() { expect(checkbox.prop('checked', false)).to.equal(checkbox); }); + + it('(invalid element/tag) : prop should return undefined', function() { + expect($(undefined).prop('prop')).to.be(undefined); + expect($(null).prop('prop')).to.be(undefined); + }); }); describe('.data', function() {