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 Traversing Filtering - filter() 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: #333; margin-bottom: 10px; } .description { margin-bottom: 20px; color: #666; } .btn { display: inline-block; padding: 10px 20px; margin-bottom: 20px; font-size: 16px; font-weight: 600; color: #fff; background-color: #3498db; border: 2px solid #2980b9; border-radius: 4px; cursor: pointer; text-decoration: none; transition: background-color 0.2s, border-color 0.2s; } .btn:hover { background-color: #2980b9; border-color: #1f6391; } .item-list { border: 2px solid #999; padding: 15px; background: #fff; width: 400px; } .item { margin: 5px 0; padding: 10px; background: #e8f6f3; border: 1px solid #76d7c4; cursor: pointer; } .item.active { font-weight: bold; border-color: #3498db; } .highlight { background: #ffebcc; border-color: #f5b041; } </style> </head> <body> <h2>jQuery Traversing Filtering - filter() Method</h2> <p class="description"> Click the button below to highlight only the <strong>active</strong> items using the <kbd>filter()</kbd> method. </p> <button id="highlight-active" class="btn">Highlight Active Items</button> <div class="item-list"> <div class="item active">Item 1 (Active)</div> <div class="item">Item 2</div> <div class="item active">Item 3 (Active)</div> <div class="item">Item 4</div> <div class="item active">Item 5 (Active)</div> </div> <script> $(function () { $('#highlight-active').on('click', function () { // Reset any previous highlights $('.item').removeClass('highlight'); // Filter only those with class .active and highlight them $('.item').filter('.active').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