Skip to content

Instantly share code, notes, and snippets.

@rafaelmaeuer
Last active August 13, 2024 14:41
Show Gist options
  • Save rafaelmaeuer/034792311997a845560b07b2a795f777 to your computer and use it in GitHub Desktop.
Save rafaelmaeuer/034792311997a845560b07b2a795f777 to your computer and use it in GitHub Desktop.

To call a function from your HTML file, include a script tag that references your JavaScript file, like above. Then, in your JavaScript file, define the function and attach it to the global object (e.g., window):

// your-script.js
function myFunction() {
  // function implementation
}
window.myFunction = myFunction;

In your HTML file, you can then call the function using its global name:

<button onclick="myFunction()">Call myFunction</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment