1️⃣ 🏠 jQuery Home – Learn jQuery for DOM, Events & Selectors
jQuery is a fast, small, and powerful JavaScript library that simplifies client-side scripting. From DOM manipulation to event handling, jQuery allows developers to build dynamic web pages with minimal code.
🧲 Introduction – Why Learn jQuery?
While modern JavaScript frameworks dominate new projects, jQuery remains crucial in maintaining legacy systems, CMS themes (like WordPress), and quick prototypes. With simple syntax, broad browser support, and excellent community documentation, it’s still a go-to for many developers.
🎯 In this guide, you’ll learn:
- How jQuery simplifies DOM, events, and Ajax handling
- Syntax and selector usage
- Event binding and chaining techniques
- Real-world applications in CMS and hybrid projects
📘 Topics Covered
🔍 Topic | 📄 Description |
---|---|
📚 jQuery Introduction | What is jQuery and why it’s still relevant |
🛠️ How to Use jQuery | Setup via CDN or local file |
🔎 jQuery Syntax Overview | Core jQuery syntax breakdown |
🏷️ jQuery Selectors | CSS-style selectors for targeting HTML elements |
🔁 jQuery Events Overview | Event handling with .on() , .click() etc. |
💡 Best Practices | Clean coding and performance tips |
🌐 Real-World Usage | Where jQuery is still used today |
📅 Summary & FAQ | Recap and common questions answered |
📚 jQuery Introduction
jQuery was developed by John Resig in 2006 and became the standard for simplifying JavaScript tasks. With concise syntax, it revolutionized how developers interact with HTML, events, and animations.
🌟 Key Features:
- Simplified DOM traversal and manipulation
- CSS-style selectors
- Cross-browser compatibility
- Ajax and animation support
- Plugin extensibility
🛠️ How to Use jQuery
➕ Include via CDN:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
💾 Or Locally:
<script src="js/jquery.min.js"></script>
✅ Place scripts before the closing </body>
tag or in the head with $(document).ready()
.
🔎 jQuery Syntax Overview
✨ Basic Syntax:
$(selector).action();
🧠 Explanation:
$
: jQuery function shortcutselector
: HTML element to targetaction()
: Method to apply
📅 Example:
<script>
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
});
});
</script>
- Waits for DOM readiness
- Adds a click event to all
<p>
tags - Hides the clicked paragraph
🏷️ jQuery Selectors
jQuery selectors use CSS syntax to find and manipulate elements.
🧩 Examples:
$("div") // All <div> elements
$("#header") // Element with id="header"
$(".menu") // Elements with class="menu"
$("ul li:first") // First <li> in each <ul>
$("input[name='q']") // Input elements with name="q"
🔗 Chaining Example:
$("a.home").parent().addClass("highlight");
- Targets
<a class="home">
- Accesses its parent
- Adds the
highlight
class
🔁 jQuery Events Overview
jQuery supports chainable event methods for dynamic interactivity.
✅ Common Syntax:
$(selector).on("event", function(){
// your code
});
🚀 Common Events:
Event | Triggered On |
---|---|
click | Mouse click |
dblclick | Double click |
mouseenter | Cursor enters element |
mouseleave | Cursor leaves element |
hover | Enters + leaves combined |
focus | Element gains focus |
blur | Element loses focus |
submit | Form submission |
change | Form input change |
keydown | Key press |
💡 Example:
$("#submitBtn").click(function(){
alert("Form submitted!");
});
💡 Best Practices
✅ Use $(document).ready()
before DOM manipulation
✅ Cache selectors in variables for performance
✅ Prefer .on()
over .click()
for dynamic elements
✅ Chain multiple methods for cleaner, faster code
Bad:
$("#box").hide();
$("#box").css("color", "red");
Good:
$("#box").hide().css("color", "red");
🌐 Real-World Usage
jQuery still powers many common interfaces:
- WordPress and Joomla themes
- Form enhancements and validations
- CMS widgets and admin panels
- Quick UIs without full frameworks
- Hybrid projects mixing old and new stacks
📅 Summary – Recap & Next Steps
jQuery remains a vital tool for developers managing legacy systems or quickly prototyping dynamic interfaces. It offers a clean, chainable syntax for common JavaScript tasks like DOM manipulation, event handling, and Ajax.
🔍 Key Takeaways:
- jQuery simplifies interactions with HTML elements
- Use
$()
to select and.on()
to bind events - Use chaining for optimized, readable code
⚙️ Real-World Relevance
jQuery is actively used in CMS development, dashboards, and systems where performance, compatibility, and ease-of-use matter more than framework complexity.
❓ FAQ – jQuery Basics
❓ What is jQuery used for?
✅ jQuery is used for DOM manipulation, event handling, animations, Ajax, and simplifying JavaScript code.
❓ How do I select elements in jQuery?
✅ Use CSS-style selectors like $("#id")
, $(".class")
, or $("tag")
.
❓ What does $(document).ready() do?
✅ It ensures the DOM is fully loaded before executing your script.
❓ What’s the difference between .on() and .click()?
✅ .on()
supports dynamic content and multiple event types, while .click()
only binds directly to existing elements.
❓ Can jQuery work with other libraries?
✅ Yes. Use $.noConflict()
to prevent conflicts when other libraries use $
.
Share Now :