Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the <script> tag not be self closed?

Tags:

html

xhtml

I had this code in my website

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"/> <script type='text/javascript' src='/lib/player/swfobject.js'></script> 

swfobject was not working (not loaded).

After altering the code to:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script> <script type='text/javascript' src='/lib/player/swfobject.js'></script> 

It worked fine.

The document was parsed as HTML5.

I think it’s funny. Okay, granted a tag that is closed and a self-closing tag are not the same. So I would understand if jQuery couldn’t load (although I find it ridiciulous).

But what I do not understand is that jQuery loads but the following, correctly written tag, doesn’t?

like image 707
The Surrican Avatar asked Dec 25 '10 21:12

The Surrican


People also ask

Is not self closing tag in HTML?

Empty HTML Elements HTML elements with no content are called empty elements. <br> is an empty element without a closing tag (the <br> tag defines a line break). Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br /> , is the proper way of closing empty elements in XHTML (and XML).

Do self closing tags need?

The fact is there is no need to close self closing tags by a slash /> at the end of the tag. Although many people use it but there is no meaning of slash at the end of the start tag even though you use it is ignored by the browsers.

Does script tag have to be in head?

The <script> Tag You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.

Does script tag have to be in body?

The script tag should always be used before the body close or at the bottom in HTML file. The Page will load with HTML and CSS and later JavaScript will load.


1 Answers

In HTML, there are tags which are always self-closed. For example, <hr>Some content here</hr> does not make any sense. In the same way, there are tags which cannot be self-closed. <script> tag is one of them.

I am not sure about the reason of no self-closed <script> tags, but the reason might come from the fact that the tag was intended to always contain code inside. Again, I'm not sure.

like image 119
Arseni Mourzenko Avatar answered Sep 19 '22 07:09

Arseni Mourzenko