The best way to integrate jQuery differs slightly based on document types:
1. HTML5 Integration
Place jQuery inside <script> tags in the <head> or before </body> for better performance.
No need to self-close <script> tags.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
console.log("jQuery is working!");
});
</script>
</body>
</html>
2. XHTML Integration
Use self-closing tags for strict syntax compliance.
Wrap JavaScript inside <![CDATA[ ... ]]> to prevent XML parsing errors.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
<![CDATA[
$(document).ready(function() {
console.log("jQuery is working!");
});
]]>
</script>
</body>
</html>