Skip to main content

Bug Tracker

Side navigation

#14487 closed bug (notabug)

Opened October 25, 2013 07:57PM UTC

Closed October 25, 2013 08:46PM UTC

Last modified September 03, 2014 06:51PM UTC

Show and hide functions don't work when there are !important styles

Reported by: lihanli Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.3
Keywords: Cc:
Blocked by: Blocking:
Attachments (0)
Change History (3)

Changed October 25, 2013 08:46PM UTC by rwaldron comment:1

resolution: → notabug
status: newclosed

Of course it doesn't, that's how "!important" works

Changed September 03, 2014 06:36PM UTC by gkertai comment:2

We've come across this same issue in our app, where we use the flex-box model extensively. Flex-box requires us to define display: box !important rules to make sure that lower priority display rules don't mess up the layout.

We're also using sortable and draggable from jQueryUI, which in turn uses jQuery.hide() to temporarily hide dragged elements, so we had to patch the jQuery.hide() function to use "display: none !important" for this (see code snippet below).

Do you see any potential problems with adding the fix to the codebase? Do you think it can hurt many users relying on this undocumented side-effect?

	// Set the display of most of the elements in a second loop
	// to avoid the constant reflow
	for ( index = 0; index < length; index++ ) {
		elem = elements[ index ];
		if ( ! ) {
		if ( !show || === "none" || === "" ) {
			// fix for hiding "display: xxx !important" elements
			if ( show ) { "display" );
				if ( values[ index ] ) { "display", values[ index ] );
			} else { "display", "none", "important" );



Changed September 03, 2014 06:51PM UTC by dmethvin comment:3

The best thing to do is not use .show() or .hide() at all. There are too many special cases to consider in order to get it right, and no amount of code will end up doing the expected thing. Just use a class name and .addClass() or .removeClass().