Posted under » JavaScript on 08 June 2009
You can call functions from other functions, from events, or from any code block.
<p id="demo"></p>
<button onclick="showHello()">Click Me</button>
<script>
function sayHello() {
return "Hello World";
}
function showHello() {
document.getElementById("demo").innerHTML = sayHello();
}
</script>
Other than logging to console, use getElementById to show your function output.
sayHello does not run the function. You must use sayHello().