0

Suppose Now I've a HTML file with

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

Both JS contain sets of functions, how can I access second.js from first.js?

i3wangyi
  • 1,319
  • 3
  • 11
  • 12

2 Answers2

1

<script> elements are executed in order. You can't access things defined in second.js while first.js is being first executed, but if you define a function in first.js and set it up so that it's called after second.js has been loaded it will see anything defined in second.js. A DOM ready or a "load" event might be a start.

Matti Virkkunen
  • 58,926
  • 7
  • 111
  • 152
0

May be you can act like this. Make it in Order.

<script type="text/javascript" src="js/first.js"></script>
<script type="text/javascript" src="js/second.js"></script>
<script>
    //call the function at first.js which will access second.js
    exampleFirstJSFunc();
</script>
Cheong BC
  • 186
  • 6