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
🔹 What is jQuery and Why
It Matters
jQuery is a lightweight, "write less, do
more" JavaScript library that simplifies programming with JavaScript and
improves the way developers write code for DOM manipulation, animations, event
handling, and AJAX operations.
✅ Key Benefits:
Feature |
Description |
Cross-Browser
Support |
Fixes
JavaScript inconsistencies across browsers |
Simplicity |
Easy syntax
for complex tasks |
Less Code |
Achieve more
with fewer lines of code |
Plugins |
Huge plugin
ecosystem for UI components |
AJAX |
Easy
asynchronous request handling |
“jQuery made JavaScript approachable — and it's still useful
today in many legacy systems and WordPress environments.”
🔹 How to Include jQuery
in Your Project
You can include jQuery via CDN (recommended) or host
it locally.
✅ Method 1: Using CDN
<script
src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
✅ Method 2: Local Installation
<script
src="js/jquery.min.js"></script>
Make sure the <script> tag is placed before the
closing </body> tag so it loads after the HTML.
🔹 Syntax Basics:
Selectors, Events, and Chaining
🔸 Basic Syntax
$(selector).action()
✅ Examples:
$("#heading").hide(); // Hides an element with ID
'heading'
$(".btn").css("color",
"red"); // Changes color of
all elements with class 'btn'
🔸 Event Handling
$(selector).on(event,
function)
Example:
$("#btn").on("click",
function() {
alert("Button clicked!");
});
🔸 Chaining
$("#box").css("color",
"blue").slideUp(2000).slideDown(2000);
Chaining allows multiple actions on the same element with
less code.
🔹 DOM Traversal and
Manipulation
jQuery provides powerful tools to manipulate and traverse
the DOM easily.
🔸 .html(), .text(),
.val()
Method |
Purpose |
Example |
.html() |
Gets or sets
HTML content |
$("#demo").html("<b>Hello</b>") |
.text() |
Gets or sets
text content |
$("#demo").text("Hello") |
.val() |
Gets or sets
input values |
$("#input").val("New
Value") |
🔸 .attr() – Get or Set
Attributes
//
Get attribute
var
href = $("a").attr("href");
//
Set attribute
$("a").attr("target",
"_blank");
🔸 Add / Remove Elements
$("#list").append("<li>New
item</li>"); // Adds at end
$("#list").prepend("<li>First
item</li>"); // Adds at start
$("#list
li:last").remove(); //
Removes last item
🔸 Table Example (DOM
Manipulation)
<table
id="userTable">
<tr><td>Name</td><td>Age</td></tr>
</table>
<button
id="addRow">Add Row</button>
javascript
CopyEdit
$("#addRow").click(function(){
$("#userTable").append("<tr><td>John</td><td>30</td></tr>");
});
🔹 Summary Table: Common
jQuery Methods
Task |
jQuery
Method |
Example |
Get/Set HTML |
.html() |
$("#demo").html("Hello") |
Get/Set Text |
.text() |
$(".box").text("Hi") |
Get/Set Input
Value |
.val() |
$("#name").val() |
Get/Set
Attribute |
.attr() |
$("a").attr("href") |
Hide/Show
Element |
.hide() /
.show() |
$("#item").hide() |
Event Binding |
.on() |
$("#btn").on("click",
fn) |
Chaining |
Multiple
methods |
$("#el").hide().fadeIn() |
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)