1

I mean, if I use JavaScript in an external file(write script code in another file, not in HTML file).

I write this code in my HTML file <script src="filename.js"></script> But this code works only if I left the tags empty.

So I'm wondering that if we use JavaScript in an external way, should I leave the tag empty as I mentioned?

3
  • en.wikipedia.org/wiki/XY_problem Commented May 31, 2020 at 16:54
  • what is the question here? Commented May 31, 2020 at 16:55
  • I mean, can I add some code between script tags that has src attribution? Commented May 31, 2020 at 17:09

1 Answer 1

1

Yes. It's important to note that a script element using the src attribute should not include additional Javascript code between the <script> and </script> tags. If both are provided, the script file is downloaded and executed while the inline code is ignored.

Reference

Note that html5 allows comments inside an external script tag. Reference html5

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it's really healful. :)
@KoreaStudent Of nothing. In the past I have also had problems with this, because I didn't know it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.