Why does not it show the expected alert? [closed]

-1

(() => {
  document.addEventListener("DOMContentloaded", () => 
    tc = document.getElementById("coor");
    tc.addEventListener("click", (evt) => {
      alert(evt.clientX);
    });
  });
})();
<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>

<body>
  <input type="button" id="coor" value="Coordenadas" />
</body>

</html>

It does not show me neither alert nor error, what I want to achieve is to show the X coordinates, by clicking the button.

    
asked by Eduardo Sebastian 01.08.2017 в 17:42
source

1 answer

3

You have the name of the badly written event. It is DOMContentLoaded no DOMContentloaded :

(()=> {      
  document.addEventListener("DOMContentLoaded",()=>{
      tc = document.getElementById("coor");
      tc.addEventListener("click", (evt) => {
         alert(evt.clientX);
      });
   });
})();
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<input type="button" id="coor" value="Coordenadas"/>
</body>
</html>
    
answered by 01.08.2017 / 17:51
source