Patrik Fröhler
Patrik Fröhler

Reputation: 1291

Call a function in html document from external javascript?

how do I call a function that I have in my html document from my external javascript file?

Upvotes: 0

Views: 100

Answers (2)

loxxy
loxxy

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

Jordan.J.D
Jordan.J.D

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

Related Questions