Why do you need to close the script tag?

2

Why open only a <script> tag does not work correctly? I know it's not the same as the CSS StyleSheets :

<link rel="stylesheet" href="assets/css/bootstrap.min.css" />

But why do I need to open and close the <script> tag, and I do not report anything inside the tag? Is not that wrong? Or is there any situation where I pass some information to tag?

<script src="assets/js/bootstrap.min.js"></script> // Sucesso

<script src="assets/js/bootstrap.min.js"> // Erro

    
asked by anonymous 28.04.2017 / 22:50

2 answers

3

What defines the requirements the syntax of the document is called "DTD - Document Type Definition "

In your specification (18.2.1 The SCRIPT element) contains this definition clearly:

  

Start tag: required, End tag: required

    
28.04.2017 / 23:26
2

Just look at the definition of the tag to understand.

Your example uses src to load an external script, but if you put the code between tags, it works. View the reference here

Here's an example:

<script>
  document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
    
28.04.2017 / 23:18