I've created few map areas in an image. I want to display the description of particular area onclick. I used one javascript function. Image contains around 15-20 map areas. Below is simple function for only 3 areas. This one working fine.
function showdiv(id) {
obj = document.getElementById(id);
alert(obj);
if (obj.style.display == 'block') {
obj.style.display = 'none';
}
if (obj.style.display == 'none') {
if (obj == whatever1) {
whatever1.style.display = 'block';
whatever2.style.display = 'none';
whatever3.style.display = 'none';
} else if (obj == whatever2) {
whatever2.style.display = 'block';
whatever1.style.display = 'none';
whatever3.style.display = 'none';
} else if (obj == whatever3) {
whatever3.style.display = 'block';
whatever2.style.display = 'none';
whatever1.style.display = 'none';
}
}
}
I believe this is method not fair for more than 15 map areas. So i tried to use for loop. But something went wrong.
<script>
function showdiv(id) {
obj = document.getElementById(id);
if (obj.style.display == 'block') {
obj.style.display = 'none';
}
if (obj.style.display == 'none') {
for (var i=0; i<=12; i++) {
var div = whatever + i;
if (div == obj) {
div.style.display = 'block';
home.style.display = 'none';
} else {
div.style.display = 'none';
}
}
}
}
</script>
What's the solution to this basic problem? Anybody have any suggestion?? Thank you so much in advance.
var div = whatever + i;- I assume in the variabledivyou are expecting a DOM element? That's not going to happen with that statement