Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery Add - prepend() Method with Callback</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <style> body { font-family: Arial, sans-serif; padding: 30px; background: #f9f9f9; } h2 { color: #222; } button { margin-top: 20px; padding: 10px 20px; background: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; } ul { margin-top: 20px; padding-left: 20px; } li { margin-bottom: 8px; color: #333; } </style> </head> <body> <h2>jQuery Add – prepend() Method with Callback</h2> <p>The <code>prepend()</code> method adds content at the start of selected elements. This version uses a callback to animate and auto-number new list items.</p> <button id="addItem">Add Item</button> <ul id="list"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul> <script> $(function(){ let count = 4; $("#addItem").click(function(){ $("#list").prepend(function(){ return "<li>Item " + count++ + "</li>"; }); }); }); </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