jQuery is a fast, small, and feature-rich JavaScript library that simplifies DOM traversal, event handling, animations, and Ajax using a concise syntax.
The core jQuery syntax follows this pattern:
// Basic jQuery syntax structure
$(selector).action();
// Hide clicked paragraph using jQuery
$(document).ready(function() {
$("p").click(function() {
$(this).hide();
});
});
This ensures the DOM is fully loaded before executing jQuery code.
// Run code after DOM is ready
$(document).ready(function() {
// jQuery code here
});
$("*") – All elements$("#id") – ID selector$(".class") – Class selector$("p") – Paragraphs$("[href]") – Attribute selector.hide(), .show(), .toggle().css(), .addClass().fadeIn(), .slideUp().on() – Event bindingChaining allows you to run multiple jQuery commands, one after the other, on the same element(s).
// Example of Chaining
$("#p1").css("color", "red").slideUp(2000).slideDown(2000);
.text() – Text only.html() – HTML content.val() – Form values$(document).ready().var $box = $("#demoBox");.on() for dynamic elements..hide() with .fadeOut()..hover()..toggleClass().