Why Self-Closing Script Elements Fail to Execute?
HTML documents with self-closing script elements, such as , are not accurately recognized by browsers, including all versions of Internet Explorer.
Understanding the XHTML Norm
The XHTML 1 specification outlines specific guidelines for element minimization in Appendix C.3:
C.3. Element Minimization and Empty Element Content Given an empty instance of an element whose content model is not EMPTY (for example, an empty title or paragraph), do not use the minimized form (e.g. use <p> </p> and not <p />).
Script Element Definition
The XHTML DTD (Document Type Definition) defines script elements as:
<!ELEMENT script (#PCDATA)>
This definition specifies that script elements are not EMPTY elements, meaning they must include content within their opening and closing tags.
Conclusion
Based on the aforementioned guidelines and definition, self-closing script elements, such as , are incorrect according to XHTML standards. As a result, browsers do not interpret these elements as valid script sources, leaving them unrecognized and preventing the execution of the referenced JavaScript code.
The above is the detailed content of Why Don't Self-Closing Script Tags Execute?. For more information, please follow other related articles on the PHP Chinese website!