Home > Web Front-end > JS Tutorial > Why Shouldn't I Use Self-Closing Script Elements in XHTML?

Why Shouldn't I Use Self-Closing Script Elements in XHTML?

Linda Hamilton
Release: 2025-01-01 13:33:11
Original
667 people have browsed it

Why Shouldn't I Use Self-Closing Script Elements in XHTML?

Self-Closing Script Elements and XHTML Support

The correct syntax for a script element in XHTML is:

<script src="foobar.js"></script>
Copy after login

Using a self-closing script element like this:

<script src="foobar.js" />
Copy after login

will not be correctly recognized by browsers. This is because the XHTML 1 specification explicitly states that for elements with a content model that is not EMPTY, the minimized form should not be used.

The script element has a content model that is not EMPTY, so the minimized form (with a trailing slash) is not valid. This is specified in the XHTML DTD as:

<!ELEMENT script (#PCDATA)>
Copy after login

Therefore, the use of self-closing script elements breaks the concept of XHTML support. Browsers will not correctly recognize these elements, and they should not be used.

The above is the detailed content of Why Shouldn't I Use Self-Closing Script Elements in XHTML?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template