Click on a button to call a function, which will output "Hello World" in an element with id="demo": - Javascript Function

Javascript examples for Function:Function Definition

Description

Click on a button to call a function, which will output "Hello World" in an element with id="demo":

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   w  w  w .  j  a va  2s . c  o m
    document.getElementById("demo").innerHTML = "Hello World";
}
</script>

</body>
</html>

Related Tutorials