Codelab Editor
Free Online HTML Editor
Run
Learn JavaScript
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Swap Box Backgrounds with jQuery</title> <style> .container { display: flex; gap: 20px; margin-bottom: 20px; } .box { width: 150px; height: 150px; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: bold; border-radius: 4px; } .box1 { background-color: #3498db; } .box2 { background-color: #e67e22; } </style> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <h2>Using Vanilla JavaScript DOMContentLoaded with jQuery</h2> <p>Click the button below to see how jQuery works inside a native DOM ready event.</p> <h3>-- Swap Box Backgrounds Example</h3> <div class="container"> <div class="box box1">Box 1</div> <div class="box box2">Box 2</div> </div> <button id="swapBtn">Swap Backgrounds</button> <script> document.addEventListener("DOMContentLoaded", function() { $("#swapBtn").on("click", function() { var box1 = $(".box1"); var box2 = $(".box2"); // Swap background colors var color1 = box1.css("background-color"); var color2 = box2.css("background-color"); box1.css("background-color", color2); box2.css("background-color", color1); }); }); </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