Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Introduction to jQuery

Lesson 25 of 34 in the free Web Technologies notes on Siksha Sarovar, written by Rohit Jangra.

Introduction to jQuery

What is jQuery?

jQuery is a fast, small, and feature-rich JavaScript library. It simplifies HTML document traversal, event handling, animation, and AJAX with an easy-to-use API that works across browsers.

CDN include:

<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>

jQuery Syntax

// $ is the jQuery function
$(selector).action();

// Wait for DOM to load
$(document).ready(function() {
    // Your code here
});

// Shorthand
$(function() {
    console.log("DOM ready");
});

Selectors

$("p")           // all <p> elements
$("#main")       // element with id="main"
$(".card")       // elements with class="card"
$("ul li")       // descendants
$("div > p")     // direct children
$("input[type='text']") // attribute
$("p:first")     // first <p>
$("tr:even")     // even table rows
$("p:contains('hello')") // contains text

DOM Manipulation

// Content
$("#title").text("New Title");
$("#box").html("<b>Bold</b>");
$("input").val("default value");

// CSS
$(".card").css("background", "#f0f0f0");
$(".card").css({ color: "red", fontSize: "18px" });

// Classes
$("div").addClass("active");
$("div").removeClass("hidden");
$("div").toggleClass("visible");
$("div").hasClass("active"); // true/false

// Attributes
$("a").attr("href", "https://example.com");
$("img").attr("src", "new.jpg");
$("input").prop("disabled", true);

Traversal

$("#item").parent();
$("#item").children();
$("#item").siblings();
$("#item").next();
$("#item").prev();
$("li").first();
$("li").last();
$("li").eq(2);          // 3rd element
$("div").find("p");     // descendants
$("p").filter(".intro"); // filter set

jQuery vs Vanilla JS

TaskjQueryVanilla JS
Select by class$('.item')document.querySelectorAll('.item')
Add class$(el).addClass('x')el.classList.add('x')
AJAX$.ajax()fetch()
Animation$(el).fadeIn()CSS transitions
Hide element$(el).hide()el.style.display='none'

When to Use jQuery in 2024

UseAvoid
Legacy projectsNew projects
Quick prototypesPerformance-critical apps
Plugin ecosystemsModern frameworks (React, Vue)
Key Takeaway: jQuery simplified cross-browser DOM manipulation for years. While modern vanilla JS and frameworks often replace it, jQuery is still widely used in legacy code and some CMS platforms like WordPress.