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 – addBack() Demo</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-right: 10px; margin-bottom: 20px; font-size: 14px; color: #fff; border: none; border-radius: 4px; cursor: pointer; } .btn-items { background: #3498db; } .btn-items:hover { background: #2980b9; } .btn-items-box { background: #27ae60; } .btn-items-box:hover { background: #1e8449; } .box { background: #fff; border: 2px solid #bdc3c7; border-radius: 6px; padding: 15px; width: 300px; } ul { padding-left: 20px; } li { margin: 5px 0; } .bold { font-weight: bold; color: #333; } .highlight-box { border-color: #f39c12 !important; background: #f39c1222; } </style> </head> <body> <h2>jQuery Traversal – addBack() Method</h2> <p>Compare how <code>addBack()</code> lets you affect both list items <em>and</em> their container.</p> <button class="btn btn-items" id="boldItems">Bold Items</button> <button class="btn btn-items-box" id="boldItemsBox">Bold Items & Highlight Box</button> <div class="box"> <h3>Grocery List</h3> <ul> <li>Apples</li> <li>Bread</li> <li>Carrots</li> <li>Detergent</li> </ul> </div> <script> $(function() { function reset() { $('.box').removeClass('highlight-box'); $('li').removeClass('bold'); } $('#boldItems').on('click', function() { reset(); // only list items become bold $('.box').find('li').addClass('bold'); }); $('#boldItemsBox').on('click', function() { reset(); // Bold items, then addBack() brings the .box into the set and highlights it $('.box') .find('li').addClass('bold') .addBack().addClass('highlight-box'); }); }); </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