Skip to content

Commit

Permalink
Fix #12336. Ensure oldIE really does .empty() selects.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmethvin committed Jan 6, 2013
1 parent b45c775 commit bbdf957
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/manipulation.js
Expand Up @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions test/unit/manipulation.js
Expand Up @@ -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" );
Expand All @@ -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() {

Expand Down

0 comments on commit bbdf957

Please sign in to comment.