user1643156
user1643156

Reputation: 4537

show elements with style display:none !important (jQuery)

As said in jQuery documentation --- .show()

Note: If using !important in your styles, such as display: none !important, it is necessary to override the style using .css('display', 'block !important') should you wish for .show() to function correctly.

But it seems the style cannot be overridden and the element cannot be shown. Am I doing anything wrong here?

jsfiddle

Upvotes: 4

Views: 34144

Answers (3)

Aufuray
Aufuray

Reputation: 21

$('.classname').attr("style", "display: block !important");

We can't use .css() here as it does not support !important.

Upvotes: 2

manavo
manavo

Reputation: 1899

Alternatively you can do it with classes (so all your CSS is in the CSS files themselves, and not being directly altered by javascript): http://jsfiddle.net/FF3mc/4/

Upvotes: 3

bart s
bart s

Reputation: 5100

When you use the attr it can work. jQueries .css() and .prop() both won't work

In this fiddle with attr remove the !important from the javascript and you will see how the CSS !important overrules even the inline styling.

your fiddle

Upvotes: 6

Related Questions