Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery Set Text 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; } p { margin-top: 10px; padding: 10px; background: #fff4e0; border-left: 4px solid #ff9800; } button { margin-top: 20px; padding: 10px 15px; background: #ff9800; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background: #e68900; } </style> </head> <body> <h1>jQuery Set Text Using Callback</h1> <p>This is the first paragraph.</p> <p>This is the second paragraph.</p> <p>This is the third paragraph.</p> <button id="updateTextBtn">Update Paragraphs with Callback</button> <script> $(document).ready(function(){ $("#updateTextBtn").click(function(){ $("p").text(function(index, currentText){ return "Updated text for paragraph " + (index + 1) + ": " + currentText; }); }); }); </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