Skip to content

Commit bbdf957

Browse files
committed
Fix #12336. Ensure oldIE really does .empty() selects.
1 parent b45c775 commit bbdf957

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/manipulation.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ jQuery.fn.extend({
192192
while ( elem.firstChild ) {
193193
elem.removeChild( elem.firstChild );
194194
}
195+
196+
// If this is a select, ensure that it displays empty (#12336)
197+
// Support: IE<9
198+
if ( elem.options && jQuery.nodeName( elem, "select" ) ) {
199+
elem.options.length = 0;
200+
}
195201
}
196202

197203
return this;

test/unit/manipulation.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ test( "detach() event cleaning ", 1, function() {
18291829

18301830
test("empty()", function() {
18311831

1832-
expect( 3 );
1832+
expect( 6 );
18331833

18341834
equal( jQuery("#ap").children().empty().text().length, 0, "Check text is removed" );
18351835
equal( jQuery("#ap").children().length, 4, "Check elements are not removed" );
@@ -1838,7 +1838,13 @@ test("empty()", function() {
18381838
var j = jQuery("#nonnodes").contents();
18391839
j.empty();
18401840
equal( j.html(), "", "Check node,textnode,comment empty works" );
1841-
});
1841+
1842+
// Ensure oldIE empties selects (#12336)
1843+
notEqual( $("#select1").find("option").length, 0, "Have some initial options" );
1844+
$("#select1").empty();
1845+
equal( $("#select1").find("option").length, 0, "No more option elements found" );
1846+
equal( $("#select1")[0].options.length, 0, "options.length cleared as well" );
1847+
});
18421848

18431849
test( "jQuery.cleanData", function() {
18441850

0 commit comments

Comments
 (0)