Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display none ! important need to override by using jQuery

Tags:

jquery

css

Anyone who is knowing how to override the below mentioned css by using jQuery ?

 .actionButton.single-pet         {             display: none !important;         } 

It won't work for this : $('.actionButton.single-pet').show();

like image 469
Sampath Avatar asked Sep 13 '13 10:09

Sampath


People also ask

Why do we use display none?

display: none; is commonly used with JavaScript to hide and show elements without deleting and recreating them.

Can jQuery override CSS?

cssHooks. Hook directly into jQuery to override how particular CSS properties are retrieved or set, normalize CSS property naming, or create custom properties.

Can we add important in jQuery?

important is used to increase the priority of a CSS property. This ignores the overriding properties. In jQuery, you can use the css() method to manipulate style property of the selector but this doesn't allow to set ! important to property.


2 Answers

$('.actionButton.single-pet').attr("style", "display: inline !important"); 

Sets CSS to display: inline !important;. display: inline is the default property for display. You need !important again to override the previous !important.

Note that !important shouldn't be used often. Read the accepted answer at How to override !important? for more details.

UPDATE: We can't use .css() here as it does not support !important. http://bugs.jquery.com/ticket/11173 for more details; appears to be a bug.

like image 50
wei2912 Avatar answered Sep 28 '22 16:09

wei2912


$('.actionButton.single-pet').removeClass('single-pet'); 

Or just:

$('.actionButton.single-pet').addClass('single-pet-shown'); 

With CSS:

.actionButton.single-pet-shown {     display: block !important; } 
like image 42
A. Wolff Avatar answered Sep 28 '22 16:09

A. Wolff