46

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();

3
  • api.jquery.com/removeClass Commented Sep 13, 2013 at 10:57
  • Does .actionButton.single-pet class has more css properties rather than display: none !important; ?
    – Mr_Green
    Commented Sep 13, 2013 at 11:08
  • @Mr_Green Nope,That is the only property.But 'actionButton' class has lot of properties.That's why I have introduced 'single-pet' class and override the display behavior of 'actionButton'.
    – Sampath
    Commented Sep 13, 2013 at 11:20

2 Answers 2

92
$('.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.

6
  • Noted, using another method. Also, I would like to know why my answer is downvoted. Thanks.
    – wei2912
    Commented Sep 13, 2013 at 10:59
  • maybe because your post is not an answer to OP's question.
    – Mr_Green
    Commented Sep 13, 2013 at 11:04
  • @Mr_Green hmm, I don't see why it isn't an answer to the OP's question.
    – wei2912
    Commented Sep 13, 2013 at 11:05
  • yeah sorry I overlooked
    – Mr_Green
    Commented Sep 13, 2013 at 11:11
  • @MathijsFlietstra there were some errors in your fiddle. I updated it. fiddle. :)
    – Mr_Green
    Commented Sep 13, 2013 at 11:16
4
$('.actionButton.single-pet').removeClass('single-pet');

Or just:

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

With CSS:

.actionButton.single-pet-shown {
    display: block !important;
}
12
  • 1
    Without the rest of his CSS and markup, this is a pure guess, not an educated answer.
    – DevlshOne
    Commented Sep 13, 2013 at 11:01
  • 1
    The OP might not want .single-pet to be removed.
    – wei2912
    Commented Sep 13, 2013 at 11:03
  • @Mr_Green No, it does not. It does not override the css property, it simply removes it. Please read the OP question again.
    – DevlshOne
    Commented Sep 13, 2013 at 11:04
  • 3
    What if .single-pet also has some other properties elsewhere in the stylesheet and they are crucial to the document's layout?
    – DevlshOne
    Commented Sep 13, 2013 at 11:05
  • 1
    @DevlshOne what if it doesn't? let just leave this to OP to decide. or if someone have better alternative then they will post it as answer.
    – Mr_Green
    Commented Sep 13, 2013 at 11:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.