-3

Really basic javascript question:

Can I save code within <script>...</script> in a different file and include it?

Will it work exactly the same?

Can I include it in the exact same place as the <script>...</script>?

Rorschach
  • 3,684
  • 7
  • 33
  • 77
  • 2
    yes, create a .js file and include it `` – Liam Feb 15 '17 at 09:55
  • this question proves a severe lack of investigation, googling "include javascript file in html" gives plenty results, not to mention it's already been asked and answered on this site too... – Brian H. Feb 15 '17 at 09:59

2 Answers2

0

Yes. Put a src attribute (where the value is the URL of the script) on the <script> element (then leave the element content empty).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

Save your Code in a file, name it xyz.js and include it:

<script src="path/xyz.js"></script>
Nightscore
  • 1
  • 1
  • 2