Adding JS script to HTML issue

Can anyone answer me why this problem occurs?

In the following code, my site only works in Chrome, only background is shown on IE7 / 8 and Firefox:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Site Title</title> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js" /> <script type="text/javascript" src="js/functions.js" /> </head> ... 

And with this code it works in Chrome, IE7 / 8 and Firefox:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="pt-br" xml:lang="pt-br"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>CSite Title</title> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript" src="js/functions.js"></script> </head> ... 

View code that does not work in Firebug. I see that the file "functions.js" is not being called, I do not understand why it does not work with " <script /> " and with " <script></script> " it works?

+4
source share
4 answers

from this ticket ( Why do self-closing script tags work? )

(note that in the indicated ticket, the accepted answer is actually not correct)

Note that IE does not support XHTML parsing. Even if you use XML declarations and / or XHTML doctrines, IE still parses the document as plain HTML. And in plain HTML, self-closing syntax is not supported. The trailing slash is simply ignored; you must use an explicit closing tag.

Even browsers that support XHTML parsing will still parse the document as HTML unless you are serving a document with the mime xml type. But in this case, IE does not display the document at all!

+12
source

Because the <script> MUST have a private tag in HTML4

Another source of information: XHTML - writes itself closing tags for elements that don't traditionally do bad practice?

+4
source

The HTML specification requires that you have an end tag for the script element. The former is invalid HTML, and the latter is.

+2
source

Closing tags that I think are best viewed in code, and I also think it's good practice. If you follow this advice, you will no longer have such problems.

+1
source

All Articles