Callback After Effects
Callback After Effects: free step-by-step lesson with examples, common mistakes, and interview tips — part of jQuery Tutorial on Toolliyo Academy.
On this page
jQuery Tutorial · Lesson 37 of 100
Callback After Effects
Setup & DOM ✓ → Events Effects AJAX → Perf & Integrate → Ship & Projects
Events Effects AJAX · 2 — Interact · ~6 min · Effects
What is this?
Most effect methods accept a complete callback that runs when the animation finishes. Use it to focus, remove nodes, or start the next action only after the UI settles.
Why should you care?
Removing a QueryVerse row before slideUp ends looks abrupt — callback removes after the motion.
See it live — copy this example
Examples include the jQuery 3.7 CDN. Paste into an HTML file or use Run Example to preview.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>QueryVerse</title>
<style>
body { font-family: system-ui, sans-serif; margin: 1.25rem; }
.box { padding: .75rem; border: 1px solid #ccc; border-radius: 8px; margin: .5rem 0; }
.muted { color: #666; }
button { margin-right: .35rem; margin-top: .35rem; }
input, select, textarea { margin: .25rem 0; }
table { border-collapse: collapse; width: 100%; }
th, td { border: 1px solid #ddd; padding: .4rem .55rem; text-align: left; }
.hidden { display: none; }
.row-odd { background: #f7f7f7; }
.active { font-weight: 700; }
.toast { background: #111; color: #fff; padding: .5rem .75rem; border-radius: 6px; }
</style>
</head>
<body>
<ul id="list" class="box">
<li>Invoice #991 <button type="button" class="del">Remove</button></li>
<li>Invoice #992 <button type="button" class="del">Remove</button></li>
</ul>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
$(function () {
$('#list').on('click', '.del', function () {
var $li = $(this).closest('li');
$li.slideUp(180, function () {
$(this).remove();
});
});
});
</script>
</body>
</html>
Run Example »
Edit the code below and click Run to see the result in Toolliyo’s live editor.
What happened?
- Callbacks receive the DOM element as this.
- If duration is 0, the callback still runs.
- Prefer promises/Deferred only when composing many async steps.
Practice next
- Remove a row and watch it slide then disappear.
- Add a fadeOut callback that focuses another control.
- Log inside the callback.
- Use .promise().done(...) on a collection of animations.
- Disable buttons until callback fires.
Remember
Complete callbacks run after fx. this is the element. Remove after hide animations.
Invoice dismiss
A ClearTax QueryVerse invoice list slides rows away before DOM removal.
Outcome: Callback remove avoids layout jump mid-animation.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!