Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>jQuery data() Example – Set Dynamic Data</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; } .item-box { padding: 15px; border: 1px solid #ccc; background: #fff; margin-bottom: 10px; max-width: 300px; } button { padding: 8px 15px; background: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer; margin-top: 20px; } </style> </head> <body> <div class="item-box">Item A</div> <div class="item-box">Item B</div> <div class="item-box">Item C</div> <button id="setDynamicData">Set Index Data</button> <script> $(document).ready(function(){ $('#setDynamicData').click(function(){ $('.item-box').each(function(index){ $(this).data('index', index + 1); $(this).append("<br><small>Index set to: " + (index + 1) + "</small>"); }); }); }); </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