So, I just tried debugging the following error:
<script>
$(function() {
div = $('<div />');
div.text('test');
div.hide(0);
div.appendto('body');
});
</script>
When I do this, the DIV is displayed. I want to hide (before we add it to the DOM). The following code:
<script>
$(function() {
div = $('<div />');
div.text('test');
div.hide();
div.appendto('body');
});
</script>
makes hides div.
When I go to jQuery source code for the hide function, I see the following:
hide: function( speed, easing, callback ) {
if ( speed || speed === 0 ) {
return this.animate( genFx("hide", 3), speed, easing, callback);
} else {
for ( var i = 0, j = this.length; i < j; i++ ) {
var display = jQuery.css( this[i], "display" );
if ( display !== "none" ) {
jQuery.data( this[i], "olddisplay", display );
}
}
for ( i = 0; i < j; i++ ) {
this[i].style.display = "none";
}
return this;
}
},
Why does he check availability
if ( speed || speed === 0 ) {
Especially, speed === 0. I would suggest when the speed is zero. You can simply skip the animation function completely and simply add a display: none; to the element.
ps. I assume that since we are giving an element that does not exist in the dom for the animation function, it just fails. Nothing needs to be revived. There, for the animation function, the DIV is not actually hidden.
:) 10 (hide()) hide (0)) . :)