Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A Quiz
🔹 1. Why Selectors,
Filters & Events Matter in jQuery
Selectors and event handlers are the core building blocks
of jQuery.
Master these, and you can control every piece of your
front-end like a pro.
🔹 2. jQuery Selectors –
The Basics
jQuery uses CSS-style selectors to target HTML
elements.
✅ Common Selector Patterns
Selector
Type |
Example |
Description |
ID |
$("#id") |
Selects
element with ID |
Class |
$(".class") |
Selects all
elements with class |
Element |
$("p") |
Selects all
<p> tags |
Attribute |
$("[type='text']") |
Input fields
of type text |
All elements |
"*" |
Selects
everything |
$("#logo").hide(); // Hide element by ID
$(".btn").css("color",
"red"); // Change text color for all buttons
🔹 3. Chaining Selectors
You can use combinations and hierarchy:
$("div
.note") // All elements with
class 'note' inside a div
$("ul
> li") // Only direct
children <li> of <ul>
$("input:checked")
// Only checked checkboxes/radios
🔹 4. Advanced Filtering
in jQuery
✅ Filter Methods
Method |
Example |
Description |
.first() |
$("li").first() |
First element
only |
.last() |
$("li").last() |
Last element
only |
.eq(index) |
$("li").eq(2) |
Element at
index 2 |
.filter() |
$("li").filter(".active") |
Only elements
with class "active" |
.not() |
$("li").not(".disabled") |
Exclude
matching elements |
$("li").filter(":odd").css("background",
"#f0f0f0");
✅ You can also chain .find(),
.children(), .parent() for DOM traversal.
🔹 5. Event Handling
Basics
✅ Syntax:
$(selector).on(event,
childSelector (optional), function)
✅ Example: Click Event
$("#submitBtn").on("click",
function() {
alert("Button was clicked!");
});
✅ Other Events:
Event Type |
Use Case |
click |
Button or
link clicks |
change |
Form input
change |
hover |
Mouse
enters/exits area |
focus/blur |
Input focus
in/out |
submit |
Form
submission |
keydown |
Keyboard
input |
🔹 6. Event Delegation
In dynamic content (like added elements), direct binding
doesn’t work.
Use event delegation instead:
$(document).on("click",
".dynamicBtn", function() {
alert("You clicked a new button!");
});
✅ This binds the event to a
static parent (document), not the dynamically created child.
🔹 7. Prevent Default
Behavior
Use .preventDefault() in event handlers to stop default
browser actions.
$("a").on("click",
function(e) {
e.preventDefault();
alert("Link clicked, but not
followed.");
});
🔹 8. Toggle, Show, Hide
Events with jQuery
jQuery allows instant UI interactivity:
$(".faq").on("click",
function() {
$(this).next(".answer").slideToggle();
});
✅ Combine this with .addClass()
and .removeClass() for styling changes.
🔹 9. Combining Selectors,
Filters & Events
Example: Make only even list items clickable.
$("ul
li").filter(":even").on("click", function() {
$(this).css("background-color",
"yellow");
});
🔹 10. Summary Table:
jQuery Selectors & Events
Task |
jQuery
Code Example |
Select by ID |
$("#elementId") |
Select by
class |
$(".btn") |
Filter
visible items |
$(".item:visible") |
Bind click
event |
$(".btn").on("click",
function...) |
Delegate
events |
$(document).on("click",
".new", fn) |
Prevent link
redirect |
$("a").on("click",
e => e.preventDefault()) |
jQuery is a fast, small JavaScript library that simplifies HTML document traversal, manipulation, event handling, and AJAX.
Yes — while modern frameworks exist, jQuery remains heavily used in WordPress, older projects, CMSs, and quick prototypes.
It shortens code, handles cross-browser issues, simplifies AJAX, and is beginner-friendly.
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
$(document).ready() runs when the DOM is ready; window.onload waits for full page (including images) to load.
$(document).ready() runs when the DOM is ready; window.onload waits for full page (including images) to load
✅ Yes — it’s open-source under the MIT license.
jQuery is a library built with JavaScript to simplify tasks like DOM handling and AJAX.
✅ Yes — it works across all major desktop and mobile browsers.
It’s better to learn JavaScript fundamentals first, but jQuery is easier to grasp early on for quick UI work.
Please log in to access this content. You will be redirected to the login page shortly.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Comments(0)