As a beginner in the realm of coding with Javascript, html, and related technologies, I am seeking guidance on how to enhance my current work.
My goal is to create a webpage featuring 4 images serving as buttons, each corresponding to 4 hidden divs with data. Initially, all divs are set to not display. The buttons successfully toggle the visibility of the corresponding divs. However, I also want to show alternative versions of the image buttons when a div is displayed.
Below is the snippet of javascript and html code I have crafted thus far:
<script type = "text/javascript">
var divState = {}
function showHide(id) {
if (document.getElementById) {
var divid = document.getElementById(id);
divState[id] = (divState[id]) ? false : true;
for (var div in divState) {
if (divState[div] && div !=id) {
document.getElementById(div).style.display = 'none';
divState[div] = false ;
}
}
divid.style.display = (divid.style.display == 'block' ? 'none' : 'block');
}
}
</script>
Here is the HTML structure:
<div id="lob">
<div id="auto">
<img src="/intact/formindem/SiteAssets/LOB/Jeep_v2.png" alt="Experts auto"
onmouseover="this.src='/intact/formindem/SiteAssets/LOB/Auto_TXT.png'"
onmouseout="this.src='/intact/formindem/SiteAssets/LOB/Jeep_v2.png'"
onclick="showHide('MSOZoneCell_WebPartWPQ3')"
width="175px" />
</div>
<div id="habitation">
<img src="/intact/formindem/SiteAssets/LOB/House_v4.png" alt="Experts habitation"
onmouseover="this.src='/intact/formindem/SiteAssets/LOB/Habit_txt.png'"
onmouseout="this.src='/intact/formindem/SiteAssets/LOB/House_v4.png'"
onclick="showHide('MSOZoneCell_WebPartWPQ4')"
width="175px" />
</div>
<div id="route">
<img src="/intact/formindem/SiteAssets/LOB/Road_v1.png" alt="Experts route"
onmouseover="this.src='/intact/formindem/SiteAssets/LOB/Route_TXT.png'"
onmouseout="this.src='/intact/formindem/SiteAssets/LOB/Road_v1.png'"
onclick="showHide('MSOZoneCell_WebPartWPQ5')"
width="175px" />
</div>
<div id="tous">
<img src="/intact/formindem/SiteAssets/LOB/All.png" alt="Tous les experts"
onmouseover="this.src='/intact/formindem/SiteAssets/LOB/Tous_TXT.png'"
onmouseout="this.src='/intact/formindem/SiteAssets/LOB/All.png'"
onclick="showHide('MSOZoneCell_WebPartWPQ6')"
width="175px" />
</div>
</div>