What is the best way to integrate jQuery in different document types like HTML5 vs XHTML

0 votes
Can i know What is the best way to integrate jQuery in different document types, like HTML5 vs. XHTML?
Mar 11 in Node-js by Ashutosh
• 23,230 points
40 views

1 answer to this question.

0 votes

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>

answered Mar 11 by Tanmay

Related Questions In Node-js

0 votes
1 answer

What is the best way to trigger change or input event in react js?

To handle change or input events in ...READ MORE

answered Feb 22 in Node-js by Kavya
73 views
0 votes
1 answer

What is the best way to handle e and props in React TypeScript?

In React with TypeScript, handling events and ...READ MORE

answered Feb 23 in Node-js by Kavya
117 views
0 votes
1 answer

What is the best way to run npm install for nested folders?

Hello @kartik, If you want to run a ...READ MORE

answered Jul 17, 2020 in Node-js by Niroj
• 82,840 points
14,888 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What is the difference between Node.js and Express.js?

Feature Node.js Express.js Definition A runtime environment for executing JavaScript outside ...READ MORE

answered Mar 11 in Node-js by Tanmay
60 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

What are the approaches to testing in React?

Testing in React ensures your components, logic, ...READ MORE

answered Dec 12, 2024 in Node-js by Navya
116 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP