Codelab Editor
Free Online HTML Editor
Run
Learn HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery Set HTML with Callback</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> <style> body { font-family: sans-serif; padding: 30px; background: #f9f9f9; } div.box { margin-top: 15px; padding: 10px; background: #fff3e0; border-left: 4px solid #fb8c00; } button { margin-top: 20px; padding: 10px 15px; background: #fb8c00; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background: #e67e00; } </style> </head> <body> <h1>jQuery Set HTML Using Callback</h1> <p>This example uses <kbd>html()</kbd> with a callback function to update each <kbd><div></kbd> individually.</p> <div class="box">Box 1 content.</div> <div class="box">Box 2 content.</div> <div class="box">Box 3 content.</div> <button id="updateHtmlBtn">Update HTML with Callback</button> <script> $(document).ready(function(){ $("#updateHtmlBtn").click(function(){ $("div.box").html(function(index, currentHtml){ return "<p>Updated HTML for div " + (index + 1) + "</p>" + currentHtml; }); }); }); </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