Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>jQuery Callbacks & Promises</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style> body { font-family: Arial, sans-serif; background: #f3f6fa; padding: 40px; text-align: center; } h2 { color: #34495e; margin-bottom: 10px; } p.description { color: #555; max-width: 600px; margin: 0 auto 30px; font-size: 15px; } .container { display: flex; justify-content: center; gap: 20px; margin-bottom: 30px; } .item { width: 80px; height: 80px; background: red; border: 2px solid #ccc; border-radius: 4px; line-height: 80px; font-weight: bold; color: #fff; cursor: pointer; transition: box-shadow 0.3s ease; } .item:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.2); } #summary { display: none; font-size: 18px; color: #27ae60; margin-top: 20px; } #startBtn { padding: 10px 20px; font-size: 15px; background: #2c3e50; color: white; border: none; border-radius: 4px; cursor: pointer; margin-top: 20px; } #startBtn:hover { background: #3e5871; } </style> </head> <body> <h2>jQuery Callbacks & Promises</h2> <p class="description"> This example uses <code>animate()</code> with delays and <code>promise()</code> to highlight items sequentially and show a summary when done. </p> <div class="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> <div class="item">4</div> </div> <button id="startBtn">Start Sequence</button> <div id="summary">All highlights completed!</div> <script> $(document).ready(function() { $('#startBtn').click(function() { $('#summary').hide(); $('.item').each(function(index) { $(this) .delay(300 * index) .animate({ opacity: 0.2 }, 300) .animate({ borderRadius: '50px' }, 300) .animate({ borderRadius: '0px' }, 300) .animate({ opacity: 1 }, 300); }); $('.item').promise().done(function() { $('#summary').fadeIn(500); }); }); }); </script> </body> </html>
Editor Commands
Ctrl
F
Find
Ctrl
G
Find Next
Ctrl
⇧
G
Find Previous
Ctrl
⇧
F
Find & Replace
Ctrl
]
Indent Code Right
Ctrl
[
Indent Code Left
⇧
Tab
Auto Indent Code
Ctrl
/
Line Comment
Ctrl
Alt
/
Block Comment
TutsInsider Actions
Alt
S
Run Code
Ctrl
C
Copy Editor Code
Ctrl
A
Select All Editor Code
Ctrl
S
Save/Download
Ctrl
Alt
X
Rotate
Ctrl
Alt
T
Switch Theme
Ctrl
⇧
C
Open Console
Esc
Close Console