So, I'm making this website as a task for school and I put following function in it.
function show() {
if(document.getElementById('benefits').style.display=='none') {
document.getElementById('benefits').style.display='block';
}
return false;
}
function hide() {
if(document.getElementById('benefits').style.display=='block') {
document.getElementById('benefits').style.display='none';
}
return false;
}
With this html code to go with it
<div id="benefits" style="display:none;"><img src="img/Bigleopard.png"id="leopard2">
<div id="upbutton"><a id="closeit" onclick="return hide();" >Return home</a></div>
</div>
I'm using the html part several times over so I can use the same function for multiple imgs on one page. The img to open can be different every time, but once I click on it, it keeps me showing the same img. So when I click on another div with a different img, the same img from the first div will show up.
EDIT***
Now I'm using different Id's on the divs and I'm using the javascript like this (Javascript has to be used for this task)
function show() {
if(document.getElementById('benefits').style.display=='none') {
document.getElementById('benefits').style.display='block';
}
return false;
}
function hide() {
if(document.getElementById('benefits').style.display=='block') {
document.getElementById('benefits').style.display='none';
}
return false;
}
function show() {
if(document.getElementById('polarbears').style.display=='none') {
document.getElementById('polarbears').style.display='block';
}
return false;
}
function hide() {
if(document.getElementById('polarbears').style.display=='block') {
document.getElementById('polarbears').style.display='none';
}
return false;
}
and these are the two divs:
<div id="benefits" style="display:none;"><img src="img/Bigleopard.png" id="leopard2">
<div id="upbutton"><a id="closeit" onclick="return hide();" >Return home</a></div>
</div>
<div id="polarbears" style="display:none;"><img src="img/Bigpolarbear.png" id="polarbear2">
<div id="upbutton"><a id="closeit" onclick="return hide();" >Return home</a></div>
</div>
After doing this, I now get the Bigpolarbear.png img to show up all the time. First it was the leopard img that showed up all the time.
I can't seem to find it out