CarpeCodice
Coder
Hi!
I have this page which displays different shield colors, depending on which TEXT is clicked (Bronze, Silver, Gold, Pro or Legend).
By default, the BRONZE shield image is showing along with the country flag image:
Then when you click on Silver, Gold, Pro or Legend, the corresponding shield image appears - below the SILVER one for example, but the country flag (a separate image) disappears:
My code follows below. I know that the javascript code hides all images that is not the selected one, and that is why the country flag disappears. But I am unable to figure out how to single out the flag image to make it visible again afterwards, or to keep it always visible. I am relatively new to coding and still learning - any help would be much appreciated. Thank you in advance!
I have this page which displays different shield colors, depending on which TEXT is clicked (Bronze, Silver, Gold, Pro or Legend).
By default, the BRONZE shield image is showing along with the country flag image:

Then when you click on Silver, Gold, Pro or Legend, the corresponding shield image appears - below the SILVER one for example, but the country flag (a separate image) disappears:

My code follows below. I know that the javascript code hides all images that is not the selected one, and that is why the country flag disappears. But I am unable to figure out how to single out the flag image to make it visible again afterwards, or to keep it always visible. I am relatively new to coding and still learning - any help would be much appreciated. Thank you in advance!
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>A2B Stat Track League</title>
<!-- Template Stylesheet -->
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<header>
<h4>Stat Track League</h4>
<h3>Cards</h3>
</header>
<div class="container">
<ul>
<li><a data-img="card-bronze" id="bronze" href="#">Bronze</a></li>
<li><a data-img="card-silver" id="silver" href="#">Silver</a></li>
<li><a data-img="card-gold" id="gold" href="#">Gold</a></li>
<li><a data-img="card-pro" id="pro" href="#">Pro</a></li>
<li><a data-img="card-legend" id="legend" href="#">Legend</a></li>
</ul>
<img class="show" id="card-bronze" src="img/card-bronze.png">
<img class="hide" id="card-silver" src="img/card-silver.png">
<img class="hide" id="card-gold" src="img/card-gold.png">
<img class="hide" id="card-pro" src="img/card-pro.png">
<img class="hide" id="card-legend" src="img/card-legend.png">
<div>
<img class="flag" src="img/flags/portugal.png">
</div>
</div>
<!-- Template Javascript -->
<script src="js/main.js"></script>
</body>
</html>
JavaScript:
var bronze = document.getElementById("bronze");
var silver = document.getElementById("silver");
var gold = document.getElementById("gold");
var pro = document.getElementById("pro");
var legend = document.getElementById("legend");
bronze.addEventListener("click", picLink);
silver.addEventListener("click", picLink);
gold.addEventListener("click", picLink);
pro.addEventListener("click", picLink);
legend.addEventListener("click", picLink);
function picLink() {
var allImages = document.querySelectorAll("img");
for (var i = 0; i < allImages.length; i++) {
allImages[i].className = "hide";
}
var picID = this.attributes["data-img"].value;
var pic = document.getElementById(picID);
if (pic.className === "hide") {
pic.className = "";
} else {
pic.className = "hide";
}
}