1. Selecting Elements
$("*") // Select all elements
$("#myId") // Select an element by ID
$(".myClass") // Select elements by class
$("div") // Select all div elements
$("div, p") // Select all div and p elements
2. Basic Methods
$("div").hide() // Hide all div elements
$("div").show() // Show all div elements
$("div").toggle() // Toggle visibility of all div elements
$("div").css("background-color", "red") // Set CSS property
$("div").attr("id", "myId") // Set attribute
$("div").html("Hello, World!") // Set HTML content
$("div").text("Hello, World!") // Set text content
3. Event Handling
$("div").click(function() {
alert("Clicked!");
}) // Bind click event
$("div").on("click", function() {
alert("Clicked!");
}) // Bind click event (newer syntax)
4. DOM Manipulation
$("div").append("Hello, World!") // Append content
$("div").prepend("Hello, World!") // Prepend content
$("div").after("Hello, World!") // Insert content after
$("div").before("Hello, World!") // Insert content before
$("div").remove() // Remove element
$("div").empty() // Empty element
5. CSS Methods
$("div").addClass("myClass") // Add class
$("div").removeClass("myClass") // Remove class
$("div").toggleClass("myClass") // Toggle class
$("div").css("background-color", "red") // Set CSS property
6. Effects Methods
$("div").fadeIn() // Fade in
$("div").fadeOut() // Fade out
$("div").slideDown() // Slide down
$("div").slideUp() // Slide up
7. Animation Methods
$("div").animate({ width: "100px" }, 1000) // Animate width
$("div").animate({ height: "100px" }, 1000) // Animate height
8. Ajax Methods
$.ajax({
type: "GET",
url: "https://api.example.com/data",
success: function(data) {
console.log(data);
}
}) // Make GET request
$.ajax({
type: "POST",
url: "https://api.example.com/data",
data: { name: "John" },
success: function(data) {
console.log(data);
}
}) // Make POST request
9. Utility Methods
$.each([1, 2, 3], function(index, value) {
console.log(value);
}) // Iterate over array
$.extend({}, { a: 1 }, { b: 2 }) // Merge objects
$.inArray(2, [1, 2, 3]) // Check if value is in array
$.isArray([1, 2, 3]) // Check if value is an array
$.isFunction(function() {}) // Check if value is a function
$.isNumeric(2) // Check if value is a number
$.isPlainObject({}) // Check if value is a plain object
$.isWindow(window) // Check if value is a window object
$.makeArray([1, 2, 3]) // Convert value to an array
$.merge([1, 2, 3], [4, 5, 6]) // Merge arrays
$.parseJSON('{"a":1}') // Parse JSON string
$.parseXML('<xml><a>1</a></xml>') // Parse XML string
$.trim(" Hello, World! ") // Trim string
10. Browser Methods
$.browser // Get browser information
$.browser.chrome // Check if browser is Chrome
$.browser.firefox // Check if browser is Firefox
$.browser.safari // Check if browser is Safari
$.browser.msie // Check if browser is Internet Explorer
$.browser.opera // Check if browser is Opera
11. CSS Selectors
$("div") // Select all div elements
$("div, p") // Select all div and <p>elements</p>
$("div.myClass") // Select all div elements with class "myClass"
$("div#myId") // Select div element with ID "myId"
$("ul li:first") // Select the first list item in a list
$("ul li:last") // Select the last list item in a list
$("ul li:even") // Select even list items
$("ul li:odd") // Select odd list items
12. Chaining Methods
$("div").css("color", "red").fadeIn().slideDown(); // Chain multiple methods
13. Form Handling
$("form").submit(function(event) {
event.preventDefault(); // Prevent default form submission
console.log("Form submitted");
});
$("input").val("Default Value"); // Set input value
let value = $("input").val(); // Get input value
14. Working with Attributes
$("img").attr("src", "image.jpg"); // Set image source
let src = $("img").attr("src"); // Get image source
$("a").prop("disabled", true); // Disable a link
15. Working with Data Attributes
$("div").data("key", "value"); // Set data attribute
let value = $("div").data("key"); // Get data attribute
16. Working with Classes
$("div").hasClass("myClass"); // Check if element has class
17. Working with the DOM
let cloned = $("div").clone(); // Clone an element
$("div").replaceWith("<p>New Element</p>"); // Replace an element
18. Working with the Window Object
$(window).resize(function() {
console.log("Window resized");
});
19. Working with the Document Object
$(document).ready(function() {
console.log("Document is ready");
});
20. Working with the Body Element
$("body").css("background-color", "blue"); // Change body background color
21. Working with the Head Element
$("head").append("<link rel='stylesheet' href='style.css'>"); // Add stylesheet
22. Working with the Title Element
$("title").text("New Title"); // Change document title
23. Working with the Meta Tags
$("head").append("<meta name='viewport' content='width=device-width, initial-scale=1'>"); // Add meta tag
24. Working with the Console
console.log("Hello, jQuery!"); // Log message to console
25. Working with the AJAX Methods
$.get("https://api.example.com/data", function(data) {
console.log(data);
}); // Make GET request
$.post("https://api.example.com/data", { name: "John" }, function(data) {
console.log(data);
}); // Make POST request
26. Working with the JSON Methods
$.getJSON("https://api.example.com/data", function(data) {
console.log(data);
}); // Make GET request for JSON data
27. Working with the Load Method
$("#myDiv").load("data.html"); // Load content from another file
28. Working with the GetScript Method
$.getScript("script.js", function() {
console.log("Script loaded");
}); // Load and execute a script
29. Working with the Deferred Object
let deferred = $.Deferred();
deferred.done(function() {
console.log("Deferred resolved");
});
deferred.resolve(); // Resolve the deferred
30. Working with the Promise Object
let promise = $.get("https://api.example.com/data");
promise.then(function(data) {
console.log(data);
}); // Handle promise resolution
31. Working with the Queue Methods
$("div").fadeOut().fadeIn(); // Queue animations
32. Working with the Stop Method
$("div").stop(); // Stop current animations
33. Working with the ClearQueue Method
$("div").clearQueue(); // Clear the animation queue
34. Working with the Promise Methods
$("div").fadeOut().promise().done(function() {
console.log("Fade out completed");
}); // Execute after fade out completes
35. Working with the Siblings
$("div").siblings(); // Get siblings of the selected element
36. Working with the Parent
$("div").parent(); // Get parent of the selected element
37. Working with the Children
$("div").children(); // Get children of the selected element
38. Working with the First and Last
$("ul li:first").css("color", "red"); // Style the first list item
$("ul li:last").css("color", "blue"); // Style the last list item
39. Working with the Filter Method
$("li").filter(".active"); // Get only active list items
40. Working with the Not Method
$("li").not(".active"); // Get all list items that are not active
41. Working with the Find Method
$("ul").find("li"); // Find all list items within a list
42. Working with the Each Method
$("li").each(function(index) {
console.log(index, $(this).text()); // Iterate over list items
});
43. Working with the Map Method
let values = $("li").map(function() {
return $(this).text(); // Get text of each list item
}).get();
console.log(values);
44. Working with the Filter Method
let filtered = $("li").filter(function() {
return $(this).text() === "Active"; // Filter active items
});
45. Working with the Reduce Method
let total = $("li").toArray().reduce((acc, li) => acc + $(li).text().length, 0); // Calculate total length of text
console.log(total);
46. Working with the Slice Method
let sliced = $("li").slice(0, 3); // Get first three list items
47. Working with the Index Method
let index = $("li").index($("#myItem")); // Get index of a specific item
48. Working with the Position Method
let position = $("#myItem").position(); // Get position of an element
console.log(position);
49. Working with the Offset Method
let offset = $("#myItem").offset(); // Get offset of an element
console.log(offset);
50. Working with the Width and Height Methods
let width = $("div").width(); // Get width of an element
let height = $("div").height(); // Get height of an element
51. Working with the InnerWidth and InnerHeight Methods
let innerWidth = $(window).innerWidth(); // Get inner width of the window
let innerHeight = $(window).innerHeight(); // Get inner height of the window
52. Working with the OuterWidth and OuterHeight Methods
let outerWidth = $("div").outerWidth(); // Get outer width of an element
let outerHeight = $("div").outerHeight(); // Get outer height of an element
53. Working with the ScrollTop and ScrollLeft Methods
let scrollTop = $(window).scrollTop(); // Get vertical scroll position
let scrollLeft = $(window).scrollLeft(); // Get horizontal scroll position
54. Working with the Animate Method
$("div").animate({ left: "+=50px" }, 1000); // Animate element to the right
55. Working with the FadeIn Method
$("div").fadeIn(1000); // Fade in element over 1 second
56. Working with the FadeOut Method
$("div").fadeOut(1000); // Fade out element over 1 second
57. Working with the SlideDown Method
$("div").slideDown(1000); // Slide down element over 1 second
58. Working with the SlideUp Method
$("div").slideUp(1000); // Slide up element over 1 second
59. Working with the Stop Method
$("div").stop(); // Stop current animations
60. Working with the ClearQueue Method
$("div").clearQueue(); // Clear the animation queue
61. Working with the Promise Methods
$("div").fadeOut().promise().done(function() {
console.log("Fade out completed");
}); // Execute after fade out completes
62. Working with the Siblings
$("div").siblings(); // Get siblings of the selected element
63. Working with the Parent
$("div").parent(); // Get parent of the selected element
64. Working with the Children
$("div").children(); // Get children of the selected element
65. Working with the First and Last
$("ul li:first").css("color", "red"); // Style the first list item
$("ul li:last").css("color", "blue"); // Style the last list item
66. Working with the Filter Method
$("li").filter(".active"); // Get only active list items
67. Working with the Not Method
$("li").not(".active"); // Get all list items that are not active
68. Working with the Find Method
$("ul").find("li"); // Find all list items within a list
69. Working with the Each Method
$("li").each(function(index) {
console.log(index, $(this).text()); // Iterate over list items
});
70. Working with the Map Method
let values = $("li").map(function() {
return $(this).text(); // Get text of each list item
}).get();
console.log(values);
71. Working with the Reduce Method
let total = $("li").toArray().reduce((acc, li) => acc + $(li).text().length, 0); // Calculate total length of text
console.log(total);
72. Working with the Slice Method
let sliced = $("li").slice(0, 3); // Get first three list items
73. Working with the Index Method
let index = $("li").index($("#myItem")); // Get index of a specific item
74. Working with the Position Method
let position = $("#myItem").position(); // Get position of an element
console.log(position);
75. Working with the Offset Method
let offset = $("#myItem").offset(); // Get offset of an element
console.log(offset);
76. Working with the Width and Height Methods
let width = $("div").width(); // Get width of an element
let height = $("div").height(); // Get height of an element
77. Working with the InnerWidth and InnerHeight Methods
let innerWidth = $(window).innerWidth(); // Get inner width of the window
let innerHeight = $(window).innerHeight(); // Get inner height of the window
78. Working with the OuterWidth and OuterHeight Methods
let outerWidth = $("div").outerWidth (); // Get outer width of an element
let outerHeight = $("div").outerHeight(); // Get outer height of an element
79. Working with the ScrollTop and ScrollLeft Methods
let scrollTop = $(window).scrollTop(); // Get vertical scroll position
let scrollLeft = $(window).scrollLeft(); // Get horizontal scroll position
80. Working with the Animate Method
$("div").animate({ left: "+=50px" }, 1000); // Animate element to the right
81. Working with the FadeIn Method
$("div").fadeIn(1000); // Fade in element over 1 second
82. Working with the FadeOut Method
$("div").fadeOut(1000); // Fade out element over 1 second
83. Working with the SlideDown Method
$("div").slideDown(1000); // Slide down element over 1 second
84. Working with the SlideUp Method
$("div").slideUp(1000); // Slide up element over 1 second
85. Working with the Stop Method
$("div").stop(); // Stop current animations
86. Working with the ClearQueue Method
$("div").clearQueue(); // Clear the animation queue
87. Working with the Promise Methods
$("div").fadeOut().promise().done(function() {
console.log("Fade out completed");
}); // Execute after fade out completes
88. Working with the Siblings
$("div").siblings(); // Get siblings of the selected element
89. Working with the Parent
$("div").parent(); // Get parent of the selected element
90. Working with the Children
$("div").children(); // Get children of the selected element
91. Working with the First and Last
$("ul li:first").css("color", "red"); // Style the first list item
$("ul li:last").css("color", "blue"); // Style the last list item
92. Working with the Filter Method
$("li").filter(".active"); // Get only active list items
93. Working with the Not Method
$("li").not(".active"); // Get all list items that are not active
94. Working with the Find Method
$("ul").find("li"); // Find all list items within a list
95. Working with the Each Method
$("li").each(function(index) {
console.log(index, $(this).text()); // Iterate over list items
});
96. Working with the Map Method
let values = $("li").map(function() {
return $(this).text(); // Get text of each list item
}).get();
console.log(values);
97. Working with the Reduce Method
let total = $("li").toArray().reduce((acc, li) => acc + $(li).text().length, 0); // Calculate total length of text
console.log(total);
98. Working with the Slice Method
let sliced = $("li").slice(0, 3); // Get first three list items
99. Working with the Index Method
let index = $("li").index($("#myItem")); // Get index of a specific item
100. Working with the Position Method
let position = $("#myItem").position(); // Get position of an element
console.log(position);