Skip to content
Advertisement

The JavaScript cannot be opened if I click the button [closed]

I have written this code.

  document.getElementById('show').onclick = function()

But I tried clicking “show” and instead it does not open and it indicates me as an error. So anyone have a solution ?

Advertisement

Answer

it’s sample on w3schools

You can try it.

    <!DOCTYPE html>
<html>
<body>

<p>This example uses the HTML DOM to assign an "onclick" event to a p element.</p>

<p id="demo">Click me.</p>

<script>
document.getElementById("demo").onclick = myFunction();

function myFunction() {
  //your codes here Zean
  document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
}
</script>

</body>
</html>
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement