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 ?
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 ?
document.getElementById('show'). addEventListener("click", function() {})
Would be the correct syntax but it really just depends what you want to do
Try function name without the brackets
document.getElementById("show").onclick = function;
See also addEventListener.
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>