Skip to main content

Bug Tracker

Side navigation

#2016 closed bug (duplicate)

Opened December 06, 2007 09:04AM UTC

Closed December 07, 2007 03:08AM UTC

Last modified March 15, 2012 07:18PM UTC

show() always uses display: block by default

Reported by: vdboord Owned by:
Priority: major Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: Cc:
Blocked by: Blocking:

The jQuery .show() method always falls back to "display: block" by default. This breaks certain elements in standard compliant browsers: table elements will not display correctly in Firefox if these get "display: block", and span/a elements somehow failed to display in Konqueror 3.5.8 when they are hidden from a global CSS file before (using "display: none").

The following code is an example how this can be fixed. In Internet Explorer, assigning an unsupported value to .display will cause an error, hence the fallback to display: block below. This has been tested to work, it only needs to be incorporated into jQuery.

try {
	// Try standard compliant value first.
	// This list is incomplete but contains the mostly used elements.
	switch( element.tagName ) {
		// Special cases
		case 'TBODY': = 'table-row-group'; break;
		case 'THEAD': = 'table-header-group'; break;
		case 'TFOOT': = 'table-footer-group'; break;
		case 'COL': = 'table-column-group'; break;
		case 'TH': = 'table-cell'; break;
		case 'TD': = 'table-cell'; break;
		case 'TR': = 'table-row'; break;
		case 'LI': = 'list-item'; break;
		// Inline elements
		case 'SPAN':
		case 'A':
		case 'IMG': = 'inline';
		// Block elements
		default: = 'block';
catch(e) {
	// Fallback for Internet Explorer when display value is unsupported. = 'block';

This fix makes workarrounds like $(el).show().css("display", "inline") obsolete.


Attachments (0)
Change History (2)

Changed December 06, 2007 07:59PM UTC by joern comment:1

The issue with workarounds like that: You can't be sure that an element that has display:inline by default really is supposed to have inline again. You'd need to check if it isn't set to block using CSS.

Just ignoring that issue could make the situation worth, because it will be even more difficult to spot errors. So far you can at least resume that you have to manually set inline when necessary

Changed December 07, 2007 03:08AM UTC by brandon comment:2

resolution: → duplicate
status: newclosed

Duplicate of #960 which has a patch.