Codelab Editor
Free Online HTML Editor
Run
Learn jQuery
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"/> <title>jQuery Traversal – add() Method</title> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <style> body { font-family: Arial, sans-serif; background: #f9f9f9; padding: 30px; } h2 { color: #2c3e50; margin-bottom: 10px; } .btn { padding: 10px 20px; margin-bottom: 20px; font-size: 14px; color: #fff; background: #8e44ad; border: none; border-radius: 4px; cursor: pointer; } .btn:hover { background: #71368a; } .item-list { border: 2px solid #bdc3c7; padding: 15px; background: #fff; width: 400px; } .item { display: inline-block; margin: 5px; padding: 10px 15px; background: #dfe6e9; border-radius: 4px; } .featured { border: 2px solid #f1c40f; } .popular { border: 2px solid #27ae60; } .highlight { background: #ffe082 !important; color: #2c3e50; } </style> </head> <body> <h2>jQuery Traversal – <code>add()</code> Method</h2> <p>Click the button to highlight both featured <em>and</em> popular items using <code>add()</code>.</p> <button class="btn" id="highlight-btn">Highlight Specials</button> <div class="item-list"> <div class="item featured">Item 1 (Featured)</div> <div class="item">Item 2</div> <div class="item popular">Item 3 (Popular)</div> <div class="item featured">Item 4 (Featured)</div> <div class="item popular">Item 5 (Popular)</div> </div> <script> $(function() { $('#highlight-btn').on('click', function() { // clear previous highlights $('.item').removeClass('highlight'); // select featured items, add popular items, then highlight both $('.featured') .add('.popular') .addClass('highlight'); }); }); </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