Codelab Editor
Free Online HTML Editor
Run
Learn CSS
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>jQuery css() with Callback Example</title> <style> body { font-family: Arial, sans-serif; padding: 40px; background-color: #f9f9f9; } h1 { color: #333; } p { font-size: 16px; color: #444; } .content-box { padding: 20px; background-color: #fff; border: 1px solid #ccc; border-radius: 6px; margin-top: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); } .item { width: 100px; height: 50px; background-color: #1CAFA3; color: white; display: inline-block; margin: 0 10px 10px 0; line-height: 50px; text-align: center; border-radius: 4px; transition: all 0.3s ease; } button { margin-top: 15px; padding: 10px 20px; background-color: #4CAF50; color: white; font-size: 14px; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #388E3C; } </style> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> </head> <body> <h1>jQuery <code>css()</code> Method – Dynamic Callback</h1> <p>Click the button to increase the width of each box by 20px times its index (0-based) using a callback function.</p> <div class="content-box"> <div class="item">Item 1</div> <div class="item">Item 2</div> <div class="item">Item 3</div> <div class="item">Item 4</div> <br/> <button id="growItemsBtn">Grow Items</button> </div> <script> $(document).ready(function() { $('#growItemsBtn').click(function() { $('.item').css('width', function(index, currentWidth) { // Parse current width (strip 'px') and add 20px times the index const cw = parseInt(currentWidth, 10); return (cw + 20 * index) + 'px'; }); }); }); </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