Home >Web Front-end >JS Tutorial >Should I Place My `` Tag Before or After the `` Tag?
Is It Acceptable to Place the <script> Tag After the <body> Tag?</script>
Placing the <script> tag after the <body> tag is not the ideal practice, but it is not necessarily detrimental.</script>
The primary concern with this placement is that it may fail validation. HTML validators expect scripts to be placed within either the
or tags.Functionally, the placement of the <script> tag outside of the <body> tag has minimal impact. However, there is a minor consideration for Internet Explorer. If DOM manipulations are performed before the body element fully loads, placing the script tag closer to the closing <body> tag may prevent potential breakage in IE.</script>
For these reasons, it is generally recommended to place the <script> tag within the <body> tag, just before the closing . This ensures validation and prevents any potential issues with DOM manipulations in IE.</script>
Example of Recommended Placement:
.... .... <script type="text/javascript" src="theJs.js"></script>
The above is the detailed content of Should I Place My `` Tag Before or After the `` Tag?. For more information, please follow other related articles on the PHP Chinese website!