14

There is a problem with a rollover doesn't want to show its content and if I do

#callCenter {
    position: fixed;
    z-index: 2411 !important;
    display: block !important; /* please note here !important */
    right: 110px;
}

It's shown, but if I do: (so the div is hidden until another element is clicked)

#callCenter {
    position: fixed;
    z-index: 2411 !important;
    right: 110px;
}

And

$('#telefonosCabecera').click(function(){
    $("#callCenter").css('display','block!important'); // or 'block !important'
    alert('done')
});

I don't see #callCenter but I do see the alert.

What could be the reason for this?

Twenty
  • 5,234
  • 4
  • 32
  • 67
Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378
  • 1
    possible duplicate of [Jquery css: applying !important styles](http://stackoverflow.com/questions/2655925/jquery-css-applying-important-styles) – Jamie Dixon Sep 12 '11 at 14:25

1 Answers1

34

You need to do one of the following:

  1. Add a class with the !important rule (i.e.: .myClass{display:block !important;} ) and then add the class to the element
  2. Add the css attribute via $('#myElement').attr('style','display: block !important');
Undo
  • 25,519
  • 37
  • 106
  • 129
Phoenix
  • 1,256
  • 2
  • 17
  • 25
  • tried that but i end up with:
    and the style attribute overrides the clasname i think :(
    – Toni Michel Caubet Sep 12 '11 at 14:37
  • 1
    The inline style ALWAYS overrides the classes. You need to pick only one of the methods. try $('#callCenter').attr('style','display: block !important'); It should do the trick for you. – Phoenix Sep 12 '11 at 15:00
  • I've found another way: http://stackoverflow.com/questions/2655925/jquery-css-applying-important-styles/8894528#8894528 – Aram Kocharyan Jan 17 '12 at 12:34
  • 2
    @Phoenix That's not true. If the inline style is not "important", it can be overridden by a class with "important" properties. Example: http://jsfiddle.net/ZpKaA/ – Lionel Oct 08 '13 at 10:43