aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUri Gilad <antishok@gmail.com>2012-07-09 23:06:51 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-07-09 23:06:51 -0400
commit21b0db7993315f0a5390798fefe63eb21891493e (patch)
tree14bfe96ca47cfe545849b6a855fe8cd26a69ae80
parent376f4e8cf637e76445082d7fdb88ab420d488b5c (diff)
downloadjquery-21b0db7993315f0a5390798fefe63eb21891493e.tar.gz
jquery-21b0db7993315f0a5390798fefe63eb21891493e.zip
Fix #11962. Standardize getter return values for empty sets.
-rw-r--r--src/manipulation.js2
-rw-r--r--src/offset.js4
-rw-r--r--test/unit/manipulation.js5
-rw-r--r--test/unit/offset.js6
4 files changed, 14 insertions, 3 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index 20b4d8d73..282307b36 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -225,7 +225,7 @@ jQuery.fn.extend({
if ( value === undefined ) {
return elem.nodeType === 1 ?
elem.innerHTML.replace( rinlinejQuery, "" ) :
- null;
+ undefined;
}
// See if we can take a shortcut and just use innerHTML
diff --git a/src/offset.js b/src/offset.js
index f8fd0ec87..db161f3ee 100644
--- a/src/offset.js
+++ b/src/offset.js
@@ -14,7 +14,7 @@ jQuery.fn.offset = function( options ) {
doc = elem && elem.ownerDocument;
if ( !doc ) {
- return null;
+ return;
}
if ( (body = doc.body) === elem ) {
@@ -103,7 +103,7 @@ jQuery.fn.extend({
position: function() {
if ( !this[0] ) {
- return null;
+ return;
}
var elem = this[0],
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 714cf02dd..525c1387b 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -1351,6 +1351,11 @@ test("html(undefined)", function() {
equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" );
});
+test("html() on empty set", function() {
+ expect(1);
+ strictEqual( jQuery( ).html(), undefined, ".html() returns undefined for empty sets (#11962)" );
+});
+
var testHtml = function(valueObj) {
expect(35);
diff --git a/test/unit/offset.js b/test/unit/offset.js
index 6a6cbcff5..348c1bd17 100644
--- a/test/unit/offset.js
+++ b/test/unit/offset.js
@@ -9,6 +9,12 @@ module("offset", { teardown: moduleTeardown });
the iframe window and the "jQuery" symbol is used to access any static methods.
*/
+test("empty set", function() {
+ expect(2);
+ strictEqual( jQuery( ).offset(), undefined, "offset() returns undefined for empty set (#11962)" );
+ strictEqual( jQuery( ).position(), undefined, "position() returns undefined for empty set (#11962)" );
+});
+
test("disconnected node", function() {
expect(2);