Why do you need to close the script tag?

Asked

Viewed 192 times

2

Why open only one tag <script> doesn’t work properly? I know it’s not the same thing as Stylesheets of CSS:

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

But why it is necessary to open and close the tag <script>, where I don’t report anything inside the tag? Isn’t 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

  • In cases where all information is present in attributes, as in your example with link, just close the tag with />.

2 answers

3


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 the tags, it also works. See the reference here

This is an example:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.