Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery Move with append() 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: 20px 0; padding: 10px 20px; background: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; } button:disabled { background: #aaa; cursor: default; } .lists { display: flex; gap: 40px; } ul { width: 200px; padding-left: 20px; background: #fff; border: 1px solid #ddd; border-radius: 4px; min-height: 120px; } li { margin-bottom: 8px; color: #333; cursor: default; } .label { font-weight: bold; margin-bottom: 8px; } #message { margin-top: 10px; color: #c00; } </style> </head> <body> <h2>Move Items Between Lists with <code>append()</code> Callback</h2> <p>Click the button to move the first item from the left list into the right list, numbering each moved item via the callback’s <code>index</code> argument.</p> <button id="moveItem">Move Item →</button> <div id="message"></div> <div class="lists"> <div> <div class="label">Source List</div> <ul id="sourceList"> <li>Apple</li> <li>Banana</li> <li>Cherry</li> <li>Date</li> </ul> </div> <div> <div class="label">Target List</div> <ul id="targetList"> <!-- moved items appear here --> </ul> </div> </div> <script> $("#moveItem").on("click", function(){ $("#targetList").append(function(){ var $item = $("#sourceList li:first"); if (!$item.length) { $("#moveItem").prop("disabled", true); $("#message").text("All items moved!"); return ""; } // Count existing items in target list to number the new one var count = $("#targetList li").length + 1; $item.text(count + ". " + $item.text()); return $item; }); }); </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