๐ฌ jQuery Effects & Animations + AJAX: Complete Guide with Real-Life Examples

Table of contents
- ๐ PART 1: Effects and Animations
- ๐น 1. hide(): Hides the selected element
- ๐น 2. show(): Displays a hidden element
- ๐น 3. fadeIn(): Fades in the element
- ๐น 4. fadeOut(): Fades out the element
- ๐น 5. slideUp(): Slide and hide the element
- ๐น 6. slideDown(): Slide and show the element
- ๐ธ 7. animate(): Create custom animations by changing CSS properties
- ๐ PART 2: AJAX with jQuery
- โ Summary
- Here's a real-life practical example :
- ๐ก Project: Live User Profile Viewer

๐ PART 1: Effects and Animations
jQuery ki special strength uske easy-to-use animations hain. Sirf 1 line mein aap kisi bhi element ko hide, show, fade ya slide kar sakte ho!
๐น 1. hide()
: Hides the selected element
$("#box").hide();
โ Use Case: Form submit karne ke baad form ko hide karna.
๐งธ Real-life Example:
<p id="note">Please read the instructions.</p>
<button id="hideNote">Hide Note</button>
$("#hideNote").click(function(){
$("#note").hide();
});
๐น 2. show()
: Displays a hidden element
$("#box").show();
๐งธ Real-life Example:
<button id="showNote">Show Note</button>
<p id="note" style="display:none;">Welcome to the website!</p>
$("#showNote").click(function(){
$("#note").show();
});
๐น 3. fadeIn()
: Fades in the element
$("#popup").fadeIn();
โ Use Case: Smoothly show a message or popup.
๐งธ Real-life Example:
<div id="popup" style="display:none;">๐ Success!</div>
<button id="successBtn">Show Success</button>
$("#successBtn").click(function(){
$("#popup").fadeIn();
});
๐น 4. fadeOut()
: Fades out the element
$("#popup").fadeOut();
๐งธ Real-life Example:
<button id="closePopup">Close</button>
<div id="popup">This is a notification</div>
$("#closePopup").click(function(){
$("#popup").fadeOut();
});
๐น 5. slideUp()
: Slide and hide the element
$("#menu").slideUp();
โ Use Case: Hide dropdown menus or FAQ sections.
๐งธ Real-life Example:
<div id="faq">This is the answer to a question.</div>
<button id="closeFaq">Close FAQ</button>
$("#closeFaq").click(function(){
$("#faq").slideUp();
});
๐น 6. slideDown()
: Slide and show the element
$("#menu").slideDown();
๐งธ Real-life Example:
<button id="openFaq">Open FAQ</button>
<div id="faq" style="display:none;">This is the answer to a question.</div>
$("#openFaq").click(function(){
$("#faq").slideDown();
});
๐ธ 7. animate()
: Create custom animations by changing CSS properties
$("#box").animate({width: "300px", height: "200px"}, 1000);
โ Use Case: Create smooth transitions and effects.
๐งธ Real-life Example:
<div id="box" style="width:100px; height:100px; background:red;"></div>
<button id="growBox">Grow Box</button>
$("#growBox").click(function(){
$("#box").animate({width: "300px", height: "300px", opacity: 0.5}, 1500);
});
๐ง Box size badh jaata hai aur transparent ho jaata hai.
๐ PART 2: AJAX with jQuery
AJAX (Asynchronous JavaScript and XML) ka use page reload kiye bina data fetch or send karne ke liye hota hai.
jQuery AJAX se aap easily server ke saath interact kar sakte ho.
๐ง What is AJAX?
AJAX allows web pages to send/receive data from server in background.
Used in real-world apps like:
Search suggestions (Google)
Auto-save (Google Docs)
Form submit without refresh
๐น 1. $.get(url, callback)
: Send GET request
$.get("data.json", function(data){
console.log(data);
});
โ Use Case: Get data from API or file.
๐งธ Real-life Example:
<button id="loadUser">Load User</button>
<p id="userInfo"></p>
$("#loadUser").click(function(){
$.get("https://jsonplaceholder.typicode.com/users/1", function(data){
$("#userInfo").text("Name: " + data.name + ", Email: " + data.email);
});
});
๐น 2. $.post(url, data, callback)
: Send POST request
$.post("submit.php", {name: "Amit"}, function(response){
console.log(response);
});
โ Use Case: Submit form data to server.
๐งธ Real-life Example:
<input type="text" id="userName" placeholder="Enter name">
<button id="submitForm">Submit</button>
<p id="responseMsg"></p>
$("#submitForm").click(function(){
var name = $("#userName").val();
$.post("submit.php", {username: name}, function(data){
$("#responseMsg").text(data);
});
});
๐น 3. $.ajax()
: Full customizable AJAX call
$.ajax({
url: "api/data",
type: "GET",
success: function(result){
console.log(result);
}
});
๐งธ Real-life Example:
<button id="getWeather">Get Weather</button>
<p id="weatherInfo"></p>
$("#getWeather").click(function(){
$.ajax({
url: "https://api.weatherapi.com/v1/current.json?key=YOUR_API_KEY&q=Delhi",
type: "GET",
success: function(data){
$("#weatherInfo").text("Temp: " + data.current.temp_c + "ยฐC");
},
error: function(){
$("#weatherInfo").text("Error fetching weather.");
}
});
});
๐ง Real-world example of getting weather data from an API.
โ Summary
Concept | Real Use Case |
hide() / show() | Toggle FAQs, alerts, modals |
fadeIn() / fadeOut() | Popups, tooltips |
slideUp() / slideDown() | Menus, collapsible sections |
animate() | Custom loading, transitions |
$.get() | Fetching data from APIs |
$.post() | Submitting forms without reload |
$.ajax() | Full control over API calls (GET/POST/etc.) |
Here's a real-life practical example :
โฌ๏ธโฌ๏ธโฌ๏ธ
โ
HTML
โ
CSS
โ
Bootstrap
โ
JavaScript
โ
jQuery with hide()
, show()
, fadeIn()
, fadeOut()
, slideUp()
, slideDown()
, animate()
โ
AJAX with $.get()
to fetch live data
๐ก Project: Live User Profile Viewer
This small web app:
Shows a user profile section.
Animates its appearance.
Fetches data using AJAX (
$.get()
from a public API).Includes buttons to show/hide/fade/slide sections.
Looks good with Bootstrap styling.
โ Step-by-Step Code:
๐ธ HTML (index.html
)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>User Profile Viewer</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
#profileCard {
display: none;
margin-top: 20px;
opacity: 0;
}
</style>
</head>
<body class="bg-light">
<div class="container py-5">
<h2 class="text-center mb-4">๐ Fetch & Animate User Profile</h2>
<div class="text-center">
<button id="loadUserBtn" class="btn btn-primary">Load Profile</button>
<button id="hideBtn" class="btn btn-secondary">Hide</button>
<button id="showBtn" class="btn btn-success">Show</button>
<button id="slideBtn" class="btn btn-warning">Slide Toggle</button>
</div>
<div id="profileCard" class="card shadow mx-auto mt-4 p-3" style="width: 22rem;">
<img src="" id="avatar" class="card-img-top rounded-circle" alt="Avatar">
<div class="card-body text-center">
<h5 class="card-title" id="userName">Loading...</h5>
<p class="card-text" id="userEmail"></p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="script.js"></script>
</body>
</html>
๐ธ JavaScript & jQuery (script.js
)
javascriptCopyEdit$(document).ready(function() {
// Load user data from API
$("#loadUserBtn").click(function() {
$.get("https://reqres.in/api/users/2", function(response) {
const user = response.data;
$("#avatar").attr("src", user.avatar);
$("#userName").text(`${user.first_name} ${user.last_name}`);
$("#userEmail").text(user.email);
// Show card with fade & animate effect
$("#profileCard").fadeIn(500).animate({opacity: 1}, 1000);
});
});
// Hide card
$("#hideBtn").click(function() {
$("#profileCard").fadeOut();
});
// Show card
$("#showBtn").click(function() {
$("#profileCard").fadeIn().animate({opacity: 1}, 500);
});
// Slide toggle card
$("#slideBtn").click(function() {
$("#profileCard").slideToggle();
});
});
๐ผ Output Preview:
Click "Load Profile" to fetch user info using AJAX.
Card appears using
fadeIn()
+animate()
.Use "Hide", "Show", and "Slide Toggle" to trigger different effects.
๐ฌ Concepts Used:
jQuery Method | Real Use |
$.get() | Fetched live user data from API |
fadeIn() | Smoothly showed the profile card |
fadeOut() | Hid the card |
animate() | Gradually changed opacity |
slideToggle() | Slid the card in and out |
This is a clean, reusable project example that you can show in your class or use as a base for larger apps like:
Employee Directory
Product Viewer
Feedback Submissions
Would you like me to add form submission using $.post()
or make it a multi-user viewer with pagination? Let me know in comment section and Iโll extend it!
Subscribe to my newsletter
Read articles from Payal Porwal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Payal Porwal
Payal Porwal
Hi there, tech enthusiasts! I'm a passionate Software Developer driven by a love for continuous learning and innovation. I thrive on exploring new tools and technologies, pushing boundaries, and finding creative solutions to complex problems. What You'll Find Here On my Hashnode blog, I share: ๐ In-depth explorations of emerging technologies ๐ก Practical tutorials and how-to guides ๐งInsights on software development best practices ๐Reviews of the latest tools and frameworks ๐ก Personal experiences from real-world projects. Join me as we bridge imagination and implementation in the tech world. Whether you're a seasoned pro or just starting out, there's always something new to discover! Letโs connect and grow together! ๐