Computer Science, asked by NobiNavita852, 1 year ago

How to call a javascript function from another javascript where both are on the another html?

Answers

Answered by brainboss1
0
I wanted to call a function defined in a first.js file in second.js file. both files are defined in an HTML file like:

<script type="text/javascript" src="first.js"></script> <script type="text/javascript" src="second.js"></script>

I want to call fn1() defined in first.js insecond.js. From my searches answers were iffirst.js is defined first it is possible but from my tests I haven't found any way to do that. Thanks

Edit:
Here's sample codes:
second.js

document.getElementById("btn").onclick = function(){ fn1(); }

first.js

function fn1(){ alert("external fn clicked"); }
Similar questions