The Ultimate Jquery Guide
The Ultimate Jquery Guide
This is the ultimate jQuery guide in which I try to cover almost all concepts of jQuery in very quick and easy
to use manner, so that you can use this guide when you want to Quickly revise jQuery. (If you want to see
complete video tutorial then from here you can see that 😍)
🧠 Table of Content:
📌 What is jQuery?
💻 How to Install jQuery in our project?
👉 Syntax of jQuery
Selectors in jQuery
🌠 Fade Effects
📨 Slide effect
🤟Modify HTML using jQuery
🤝 Modify CSS using jQuery
💌 AJAX in jQuery
📌 What is jQuery?
jQuery is the lightweight and most popular JavaScript library for simplified some JavaScript
Code.
For example, We want to add Click event to one button or we want to hide some elements on our
HTML page or we want to remove/add CSS class from some elements, all this type of thing we can
also do it in Vanilla JavaScript but using jQuery we can do that more easily.
Here is the example of Code for Adding click event for button in JavaScript: (This is just for example)
element.addEventListener("click", function() {
document.getElementById("output").innerHTML = "Good Morning!";
});
Now let’s see how we can do this same this in jQuery code:
Remember one thing, jQuery is not about replacing JavaScript completely. jQuery is for making
our code less for some features. We will see all that features in this guide.
So Open this link 🔗 and Copy CDN link of Latest jQuery and paste it before your main JavaScript file, so
you can use it in your JavaScript file.
..
...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="js/script.js"></script> <!-- This is your main JavaScript file in which you will write code -->
👉 Syntax of jQuery
Syntax of jQuery is pretty simple for most jQuery code. Note that, this syntax is not for all jQuery code
but it will cover most of them.
jQuery Selectors works with HTML DOM elements like name, id, classes, types, attributes, values of
attributes, and many more.
If you want to learn more selector than you can refer this table.
Syntax Description
$("*") Selects all elements
$(this) Selects the current HTML element
$("p.intro") Selects all <p> elements with class="intro"
$("a[target!='_blank']") Selects all <a> elements with a target attribute value NOT equal to "_blank"
🤯 Events in jQuery
Events are the very important part of any webpage. It is basically a response for the user actions.
1. Mouse events
2. Keyboard events
3. Form events
// click event
$("#btn").click(function() {
$("p").hide();
});
// Keydown event
$("#nameInput").keydown(function() {
console.log("Keydown event called!")
});
This function will run when this event is called. All events are pretty simple, you can try them all by
yourself.
// Hide method
$("#hide").click(function(){
// Show method
$("#show").click(function(){
$("p").show();
});
We can also pass here speed in miliseconds like 1000, 2000, 5000 or “slow” or “fast” and callback
function in hide and show methods:
// Show method with slow animation and callback run after show effect will end
$("#show").click(function(){
$("p").show("slow", function() {
console.log("This callback function will run after show method complete");
});
});
$("button").click(function(){
$("p").toggle();
});
🌠 Fade Effects
With jQuery you can fade an element in and out of visibility.
Here is an example of fadeIn() effect. Note that you have to hide that element first.
// fadeIn effect
$("#btn_show").click(function(){
$("#p1").fadeIn();
$("#p2").fadeIn("slow");
$("#p3").fadeIn(3000);
});
// fadeTo effect
$("#btn_show").click(function() {
📨 Slide effect
With jQuery you can create a sliding effect on elements.
$("#btn_flip").click(function(){
$("#panel").slideUp();
});
$("#btn_flip").click(function(){
$("#panel").slideToggle("slow");
});
2. html() - used to set or get the content with HTML markup of selected elements
// HTML Code
<p id="sample">This is sample <b>paragraph</b> for jQuery</p>
<button id="manage" value="BTN">Manage Account</button>
//jQuery Code
$("#sample").text(); // Output: This is sample paragraph for jQuery
So, text() method will return only the text of jQuery, but html() method will return text with other
HTML markup.
These methods we can use for creating little animations on our website.
3. toggleClass() - used to toggle Class to selected element (This technique I use for sidebar
animations)
$("btn_add").click(function(){
$("h1, h2, p").addClass("blue");
$("div").removeClass("important");
});
💌 AJAX in jQuery
AJAX stands for Asynchronous JavaScript and XML.
AJAX is important for loading data from API/server without reloading the full page.
Many popular applications like Gmail, Instagram, Facebook, Youtube and many more using AJAX for
loading data in the background.
2. get() - used to load data from the server using HTTP GET request
3. post() - used to send and load data from the server using HTTP POST request
$.get("https://jsonplaceholder.typicode.com/users",
function (data, status) {
console.log(data);
console.log(status);
}
);
$.post("https://jsonplaceholder.typicode.com/posts",
{ title: "This is title", body: "This is body" },
function (data, status) {
console.log(data, status);
}
);
So, I try to cover almost all-important topics of jQuery JavaScript library which will make our Code
easy and short. Practice some jQuery on your project and I am sure you will like jQuery a lot.
If you want to see the Full Tutorial of jQuery step by step, then Open this link 🔗 and watch complete
jQuery tutorial.