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 - odd() 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: #8e44ad; border: 2px solid #7d3c98; border-radius: 4px; cursor: pointer; text-decoration: none; transition: background-color 0.2s, border-color 0.2s; } .btn:hover { background-color: #7d3c98; border-color: #6c3483; } .item-list { border: 2px solid #999; padding: 15px; background: #fff; width: 400px; } .item { margin: 5px 0; padding: 10px; background: #e8f6f3; border: 1px solid #76d7c4; } .highlight { background: #f9ebea; border-color: #ec7063; } </style> </head> <body> <h2>jQuery Traversing Filtering - odd() Method</h2> <p class="description"> Click the button below to highlight all <strong>odd-indexed</strong> items (1, 3, 5...) using the <kbd>odd()</kbd> method. </p> <button id="highlight-odd" class="btn">Highlight Odd Items</button> <div class="item-list"> <div class="item">Item 1</div> <div class="item">Item 2</div> <div class="item">Item 3</div> <div class="item">Item 4</div> <div class="item">Item 5</div> <div class="item">Item 6</div> </div> <script> $(function () { $('#highlight-odd').on('click', function () { $('.item').removeClass('highlight'); // reset $('.item').odd().addClass('highlight'); // highlight odd index items }); }); </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