FranciscoRibeiro
FranciscoRibeiro

Reputation: 1

How do I reset an image, after being removed, using if assignment, in javascript

With this function I am able to remove these two images from the webpage

function removeElement(){
    document.getElementById("imgbox1").style.display = "none";
    document.getElementById("imgbox2").style.display = "none";

And with this function I am able to reset the images, after I click on a button

function resetElement(Ali){
    document.getElementById("imgbox3").style.display = "block";
    
    if (Ali = "Mono"){
    document.getElementById("imgbox1").style.display = "block";
    }
    else if(Ali = "Tri"){
    document.getElementById("imgbox2").style.display = "block";
    }
}

With the code that I have I am able to reset the first image, however I which to be able to reset the second image using an if assignment. I am having trouble with the if's, because the code is only going through the first if.

Upvotes: 0

Views: 27

Answers (2)

Gopal Lohar
Gopal Lohar

Reputation: 193

Man You put a single equal there ! do == or === then this thing will definetly work by resetElement("Mono"); and resetElement("Tri);

Upvotes: 0

Azura's Starfish
Azura's Starfish

Reputation: 122

No matter what, only one of the two if-blocks in resetElement() will ever be executed in a single call to the function, because Ali will either equal "Mono" or "Tri" (or maybe neither) but never both.

The only way to execute both would be to call the function twice with different arguments, eg:

resetElement("Mono");
resetElement("Tri);

Upvotes: 1

Related Questions