jQuery CSS Opacity
Asked Answered
C

4

61

What's wrong? I want to change the opacity if #nav .drop is display:block;

jQuery(document).ready(function(){
    if (jQuery('#nav .drop').css('display') === 'block') {
        jQuery('#main').css('opacity') = '0.6';
    }
});
Chaps answered 7/5, 2013 at 13:54 Comment(2)
Try this jQuery('#main').css({'opacity':0.6}) ;Floatation
Is this for a drop down menu? Presumably if the drop is not display: block it is hidden, so why not just set it permanently to 60% opacity? Or am I missing something? It would be nice to see a working example of this.Kamp
B
130
jQuery('#main').css('opacity') = '0.6';

should be

jQuery('#main').css('opacity', '0.6');

Update:

http://jsfiddle.net/GegMk/ if you type in the text box. Click away, the opacity changes.

Brita answered 7/5, 2013 at 13:57 Comment(2)
yep, found that just in time, but it still dont work. Any other idea?Chaps
Opacity value should not be a string, so: 'jQuery('#main').css('opacity', 0.6);'Unfathomable
N
28

Try with this :

jQuery('#main').css({ opacity: 0.6 });
Naara answered 7/5, 2013 at 13:56 Comment(0)
W
15

Try this:

jQuery('#main').css('opacity', '0.6');

or

jQuery('#main').css({'filter':'alpha(opacity=60)', 'zoom':'1', 'opacity':'0.6'});

if you want to support IE7, IE8 and so on.

Westberg answered 23/4, 2014 at 17:31 Comment(0)
M
0

try using .animate instead of .css or even just on the opacity one and leave .css on the display?? may b

jQuery(document).ready(function(){
if (jQuery('#nav .drop').animate('display') === 'block') {
    jQuery('#main').animate('opacity') = '0.6';
Monotint answered 7/12, 2015 at 6:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.