Skip to content
Permalink
Browse files

Make sure that hide or show don't fail when operating on non-Element …

…nodes. Fixes #6135.
  • Loading branch information...
jeresig committed Apr 17, 2011
1 parent 728a70c commit 21c0be8496127df3f0ad652e582133148430cc41
Showing with 27 additions and 15 deletions.
  1. +23 −15 src/effects.js
  2. +4 −0 test/unit/effects.js
@@ -28,30 +28,36 @@ jQuery.fn.extend({
} else {
for ( var i = 0, j = this.length; i < j; i++ ) {
elem = this[i];
display = elem.style.display;

// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
display = elem.style.display = "";
}
if ( elem.style ) {
display = elem.style.display;

// Reset the inline display of this element to learn if it is
// being hidden by cascaded rules or not
if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
display = elem.style.display = "";
}

// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
// Set elements which have been overridden with display: none
// in a stylesheet to whatever the default browser style is
// for such an element
if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
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];
display = elem.style.display;

if ( display === "" || display === "none" ) {
elem.style.display = jQuery._data(elem, "olddisplay") || "";
if ( elem.style ) {
display = elem.style.display;

if ( display === "" || display === "none" ) {
elem.style.display = jQuery._data(elem, "olddisplay") || "";
}
}
}

@@ -75,7 +81,9 @@ jQuery.fn.extend({
// Set the display of the elements in a second loop
// to avoid the constant reflow
for ( i = 0; i < j; i++ ) {
this[i].style.display = "none";
if ( this[i].style ) {
this[i].style.display = "none";
}
}

return this;
@@ -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() {

0 comments on commit 21c0be8

Please sign in to comment.
You can’t perform that action at this time.