Add an onclick event attribute to <button>. Clicking the button should trigger myFunction(). - Javascript DOM

Javascript examples for DOM:Quiz

Description

Add an onclick event attribute to <button>. Clicking the button should trigger myFunction().

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Click Me</button>

<p id="demo"></p>

<script>
function myFunction() {//from www .  j a v  a2  s. c o  m
    document.getElementById("demo").innerHTML = "Hello World";
}
</script>

</body>
</html>

Related Tutorials