Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142100

Why is onclick not working in JavaScript? [duplicate]

$
0
0

This question already has an answer here:

I wrote a simple code to learn Eventhandling in JavaScript but when I click on the button "Click" the function hello() does not work, why?

html file:

<!DOCTYPE html>
<html>
  <head>
    <script src="hello.js"></script>
  </head>
  <body>
    <button id="click">Click</button>
  </body>
</html>

JavaScript file:

    document.getElementById("click").onclick = hello;
    function hello() {
      alert("You Clicked!");
     }

Viewing all articles
Browse latest Browse all 142100

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>