30

How do I check if the opacity of an element is 0, and then do something in jQuery?

Chad
  • 1,531
  • 3
  • 20
  • 46
James
  • 42,081
  • 53
  • 136
  • 161

6 Answers6

68

Have you tried using .css()?

if($('elemFoo').css('opacity') == 0) {
    doSomething();
}
Christian Mann
  • 8,030
  • 5
  • 41
  • 51
2

You can do as

$(function() {

    if ($('#foo').css('opacity') == 0)
        alert('lol');

});

Demo : http://jsfiddle.net/9GEZ5/

GG.
  • 21,083
  • 14
  • 84
  • 130
  • @ggregorie, that will set the opacity to 0. The poster wants to check if the opacity is 0. The way to get the value is to mentioned in other people's answers. – sarcastyx Mar 14 '11 at 01:07
1
if( $("#id_of_your_thing").css('opacity') == "0" )
  do_stuffs();
Groovetrain
  • 3,315
  • 19
  • 23
0
jquery.support.opacity

on jQuery 1.7.1 seems to work

Mark
  • 3,334
  • 1
  • 22
  • 27
0
var currentOpacity = jQuery.fx.step.opacity

if(currentOpacity == 0)
{
   ...
ukhardy
  • 2,084
  • 1
  • 13
  • 12
0

To find opacity you do

var x = $('#test').css('opacity');
x==0 ? alert('opacity is 0') : alert('Opacity is not 0');

Check working example at http://jsfiddle.net/SCHNc/1/

Hussein
  • 42,480
  • 25
  • 113
  • 143