How to call a javascript function from another javascript where both are on the another html?
Answers
Answered by
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"); }
<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
Math,
6 months ago
Social Sciences,
6 months ago
Hindi,
6 months ago
Math,
1 year ago
English,
1 year ago