Reputation: 1291
how do I call a function that I have in my html document from my external javascript file?
Upvotes: 0
Views: 100
Reputation: 13151
When the external javascript is included in the page it has access to every function on the page as well as functions in other JS files included on the page.
This is assuming none of the functions are wrapped in a namespace...
Upvotes: 5
Reputation: 8113
Javascript file:
function functionName()
{
some code to be executed
}
Html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button onclick="functionName()">Try it</button>
</body>
</html>
Upvotes: 1