mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Make sure that hide or show don't fail when operating on non-Element nodes. Fixes #6135.
This commit is contained in:
parent
728a70c036
commit
21c0be8496
8
src/effects.js
vendored
8
src/effects.js
vendored
@ -28,6 +28,8 @@ jQuery.fn.extend({
|
||||
} else {
|
||||
for ( var i = 0, j = this.length; i < j; i++ ) {
|
||||
elem = this[i];
|
||||
|
||||
if ( elem.style ) {
|
||||
display = elem.style.display;
|
||||
|
||||
// Reset the inline display of this element to learn if it is
|
||||
@ -43,17 +45,21 @@ jQuery.fn.extend({
|
||||
jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set the display of most of the elements in a second loop
|
||||
// to avoid the constant reflow
|
||||
for ( i = 0; i < j; i++ ) {
|
||||
elem = this[i];
|
||||
|
||||
if ( elem.style ) {
|
||||
display = elem.style.display;
|
||||
|
||||
if ( display === "" || display === "none" ) {
|
||||
elem.style.display = jQuery._data(elem, "olddisplay") || "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -75,8 +81,10 @@ jQuery.fn.extend({
|
||||
// Set the display of the elements in a second loop
|
||||
// to avoid the constant reflow
|
||||
for ( i = 0; i < j; i++ ) {
|
||||
if ( this[i].style ) {
|
||||
this[i].style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
4
test/unit/effects.js
vendored
4
test/unit/effects.js
vendored
@ -88,6 +88,10 @@ test("show()", function() {
|
||||
var elem = jQuery(selector, "#show-tests").show();
|
||||
equals( elem.css("display"), expected, "Show using correct display type for " + selector );
|
||||
});
|
||||
|
||||
// Make sure that showing or hiding a text node doesn't cause an error
|
||||
jQuery("<div>test</div> text <span>test</span>").show().remove();
|
||||
jQuery("<div>test</div> text <span>test</span>").hide().remove();
|
||||
});
|
||||
|
||||
test("show(Number) - other displays", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user