Display conditional problem in Js

5

I'm trying to create a conditional with display: block; and display: none; but JS is not bringing the value of the css display of my #slide element.

What is the problem?

var slider = document.getElementById('slide');
if(slider.style.display == 'block'){
   alert('teste');
}
    
asked by anonymous 13.02.2014 / 14:53

1 answer

5

A very likely cause is that the% cos_de% property is actually blank. A simple solution is to invert the logic:

var slider = document.getElementById('slide');
if(slider.style.display !== 'none'){
   alert('visível');
} else {
   alert('oculto');    
}
    
13.02.2014 / 14:57