Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
How to link Mapping in HTML with the js alert function

I've been experimenting with using mapping in html creating links I'd like to make it so that when you click on a spot on the webpage an alert button would come up saying "Possible Murder Weapon!"

Right now I have..

<body id="House1">
<img src="png/1House.png" alt="House 1" usemap="#Items" height="1100px" width="1100px">
<map name="House1">
<area shape="rect" coords="739,917,856,1032" alt="Mug" href="alert.js">
</map>
</body>

Inside the file alert.js I have..

alert("Possible Murder Weapon!");

How would I be able to fix my code in the most minimalistic way? (I don't know a ton about coding)

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You will also have to link the map to your image by specifying the map's name (here: mughouse) in the <img>'s usemap attribute as #mughouse:

let mug = document.getElementById("mug");
mug.onclick = function() {
  alert('Possible Murder Weapon: the gate!');
};
<img usemap="#mughouse" src="https://jmorton01.files.wordpress.com/2011/11/192898_230170753687660_100000842118185_640954_2587551_o.jpg" alt="House 1" usemap="#Items">
<map name="mughouse">
    <area shape="rect" coords="285,327,363,449" title="Here it is!" href="#" id="mug">
  </map>

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try simply below code !!

<area shape="rect" coords="739,917,856,1032" alt="Mug" href="#!" onclick="alert('Possible Murder Weapon!');">

(or) with script tag

<body id="House1">
  <img src="png/1House.png" alt="House 1" usemap="#Items" height="1100px" width="1100px">
  <map name="House1">
    <area shape="rect" coords="739,917,856,1032" alt="Mug" href="#!" id="mug">
  </map>

  <script>
    let mug= document.getElementById("mug");
    mug.onclick = function () {
     alert('Possible Murder Weapon!');
    };
  </script>
</body>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda