But it works ? Firefox 3.5....">

Html script tag

Why does this work not work

<script src="jquery.js"/>

But it works

<script src="jquery.js"></script>

?

Firefox 3.5.8

+3
source share
2 answers

Because:

<script src="jquery.js"/>

is valid XML (including XHTML), but not valid HTML.

See 18.2.1 SCRIPT Element :

18.2.1 SCRIPT Element

<!ELEMENT SCRIPT - - %Script;          -- script statements -->
<!ATTLIST SCRIPT
  charset     %Charset;      #IMPLIED  -- char encoding of linked resource --
  type        %ContentType;  #REQUIRED -- content type of script language --
  src         %URI;          #IMPLIED  -- URI for an external script --
  defer       (defer)        #IMPLIED  -- UA may defer execution of script --
  >

Start tag: required ; end tag: required

+7
source

The script element is not defined as EMPTY (since you can embed the script directly inside it), therefore, an end tag is required in HTML, therefore you cannot have something that is (in terms of soup-soup) a start tag with a random character /in it. representing the whole element.

, : http://www.w3.org/TR/xhtml-media-types/#C_2

0

Source: https://habr.com/ru/post/1735858/


All Articles