From: Dave Methvin Date: Sun, 6 Jan 2013 19:20:35 +0000 (-0500) Subject: Fix #12336. Ensure oldIE really does .empty() selects. X-Git-Tag: 1.9.0rc1~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bbdf957e9886212cac9b72ee9dedd73118aa8427;p=jquery.git Fix #12336. Ensure oldIE really does .empty() selects. --- diff --git a/src/manipulation.js b/src/manipulation.js index 5fec948cb..e8c0fe46f 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -192,6 +192,12 @@ jQuery.fn.extend({ while ( elem.firstChild ) { elem.removeChild( elem.firstChild ); } + + // If this is a select, ensure that it displays empty (#12336) + // Support: IE<9 + if ( elem.options && jQuery.nodeName( elem, "select" ) ) { + elem.options.length = 0; + } } return this; diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 86b26e040..d208b3b7a 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1829,7 +1829,7 @@ test( "detach() event cleaning ", 1, function() { test("empty()", function() { - expect( 3 ); + expect( 6 ); equal( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" ); equal( jQuery("#ap").children().length, 4, "Check elements are not removed" ); @@ -1838,7 +1838,13 @@ test("empty()", function() { var j = jQuery("#nonnodes").contents(); j.empty(); equal( j.html(), "", "Check node,textnode,comment empty works" ); -}); + + // Ensure oldIE empties selects (#12336) + notEqual( $("#select1").find("option").length, 0, "Have some initial options" ); + $("#select1").empty(); + equal( $("#select1").find("option").length, 0, "No more option elements found" ); + equal( $("#select1")[0].options.length, 0, "options.length cleared as well" ); + }); test( "jQuery.cleanData", function() {