How do I check if the opacity of an element is 0, and then do something in jQuery?
Asked
Active
Viewed 4.5k times
6 Answers
68
Have you tried using .css()?
if($('elemFoo').css('opacity') == 0) {
doSomething();
}

Christian Mann
- 8,030
- 5
- 41
- 51
-
Anyone know the JavaScript equivalent – TheBlackBenzKid Mar 23 '15 at 16:59
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
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