The script works fine for #myLinks but it's not working properly for #myLinks2.
The only thing working for #myLinks2 is the picture change
style
function opentest(x) {
var y = document.getElementById(x);
if (y.style.display === "block") {
if (x == 'myLinks') {
document.getElementById('citypart').src = "pic/plus.png";
}
if (x == 'myLinks2') {
document.getElementById('roadpart').src = "pic/plus.png";
}
y.style.display = "none";
} else {
if (x == 'myLinks') {
document.getElementById('citypart').src = "pic/minus.png";
}
if (x == 'myLinks2') {
document.getElementById('roadpart').src = "pic/minus.png";
}
y.style.display = "block";
}
}
#myLinks {
display: none;
}
#myLinks2 {
display: none;
}
<a onclick="opentest('myLinks')" style="background-color:#ccc;color: white;">
<img id="citypart" src="pic/plus.png" height="42" width="42"> travel to
</a>
<div id="myLinks">
<a href="athen.php">----Athen</a>
</div>
<a onclick="opentest('myLinks2')" style="background-color:#ccc;color: white;">
<img id="roadpart" src="pic/plus.png" height="42" width="42"> tour type
</a>
<div id="myLinks2">
<a href="city.php">----Per city</a>
</div>