so I made a mapped image in html/css/javascript. I made it so when I click on an area a function get's called that makes a modal appear, the content depends on the location.hash that changes due to the href attribute in the mapped areas. The thing is, it is always the previous hash and not the current one, for example:
- #hash1
- #hash2, location.hash returns: #hash1
- #hash3, location.hash returns: #hash2
- #hash4, location.hash returns: #hash3
- #hash5, location.hash returns: #hash4
- #hash6, location.hash returns: #hash5
- #hash7, location.hash returns: #hash6
etc.
Why is that? And how do I fix this?
summary of the code I use:
<img src="image.png" width="300" height="300" usemap='#modalmap'>
<map name="modalmap">
<area shape="rect" coords="0,0,150,150" alt="topleft" href="#topleft" target="_self" title="topleft" onclick="appearModal(event)">
<area shape="rect" coords="150,0,300,150" alt="topright" href="#topright" target="_self" title="topright" onclick="appearModal(event)">
<area shape="rect" coords="0,150,150,300" alt="bottomleft" href="#bottomleft" target="_self" title="bottomleft" onclick="appearModal(event)">
<area shape="rect" coords="150,150,300,300" alt="bottomright" href="#bottomright" target="_self" title="bottomright" onclick="appearModal(event)">
</map>
<script>
function appearModal(event){
switch(location.hash){
case "#topright":
console.log(location.hash);
break;
case "#bottomright":
console.log(location.hash);
break;
case "#bottomleft":
console.log(location.hash);
break;
case "#topleft":
console.log(location.hash);
break;
default:
console.log(location.hash);
}
</script>