jQuery code is written inside the JavaScript script tag.
Without the script tag, the browser cannot understand jQuery code.
jQuery can be written directly inside HTML or inside a separate JavaScript file.
Both methods are used in real-world projects.
This method is suitable for small examples and learning purposes.
However, it is not recommended for large projects.
In real projects, jQuery code is usually written inside a separate JavaScript file.
This keeps HTML clean and organized.
This code is written inside a separate JavaScript file and works the same way.
jQuery must be loaded before this file.
Best Practices:
- Use script tag for small testing
- Use external JS file for projects
- Load jQuery before custom file
- Keep code clean and readable