Skip to content

Instantly share code, notes, and snippets.

@markelog
Created May 15, 2012 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markelog/2706036 to your computer and use it in GitHub Desktop.
Save markelog/2706036 to your computer and use it in GitHub Desktop.
disconnected nodes and css
// suppose we have this in css
// .hidden { display: none; }
// .inline { display: inline; }
// then in javascrpit
$('<div class="hidden"/>').css("display");
// for FF – "none"
// for IE – "block"
// For Chrome, Opera – ""
$('<div class="inline"/>').css("display");
// for FF – "inline"
// for IE – "block"
// For Chrome, Opera – ""
// with current code if you do
$('<div class="hidden"/>').fadeIn() | show( 0 ) | fadeTo();
$('<div class="inline"/>').fadeIn() | show( 0 ) | fadeTo();
// it will set display to "block"
// but with pull 774
$('<div class="hidden"/>').fadeIn() | show( 0 ) | fadeTo();
// FF will change display, when others will not
$('<div class="inline"/>').fadeIn() | show( 0 ) | fadeTo();
// display will not be set for all browsers
// but for
$('<div class="hidden"/>').show();
$('<div class="inline"/>').show();
// display will always be set
// so we should also check for disconnected nodes, something like this –
jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument.documentElement, elem );
// Also, there issue with height: 0; elements
// now it's like this – http://jsfiddle.net/z9r2e/
// because test for visibility in showHide and defaultPrefilter functions are different
// but with 774 change test will be identical, so it will always hide elements like that
// really, i don't see a problem with it, for me, it looks like more righteous behavior,
// for me, present behavior looks like bug
// and this
jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument.documentElement, elem );
// still faster than this
jQuery( elem ).is(":hidden");
// http://jsperf.com/ishidden-vs-hidden
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment