Skip to content Skip to sidebar Skip to footer

Function Doesn't Work

I need a little help with this function: function passar() { var fotos1 = document.getElementById('foto1'); var fotos2 = document.getElementById('foto2'); var fotos3

Solution 1:

= for assignment

== for comparison

=== for strict comparison

if (fotos1.style.display === "block") {   
fotos1.style.display = "none";  
fotos2.style.display = "block";  
 } elseif (fotos1.style.display === "none") {  
 fotos2.style.display = "none";    
  }  
} 

Solution 2:

Your conditional statement is doing an assignment rather than a comparison:

if (fotos1.style.display === "block") {   
    fotos1.style.display = "none";  
    fotos2.style.display = "block";  
} elseif (fotos1.style.display === "none") {  
    fotos2.style.display = "block";    
}

Also, it is recommended to use strict comparison using === over the weak comparison ==. You get the added benefit of the comparison also being roughly 4X faster in some browsers.

Solution 3:

You should be using a comparison operator which is double equals in this case:

if (fotos1.style.display == "block") {

Instead you are using a single equals which is an assignment parameter:

if (fotos1.style.display = "block") {

Post a Comment for "Function Doesn't Work"