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 prevUntil() – Highlight Previous Siblings Until Target</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; } .description { color: #555; margin-bottom: 20px; } .container { background: #fff; border: 2px solid #ccc; padding: 20px; width: 400px; } .item { background: #d0ebff; border: 1px solid #74c0fc; padding: 10px; margin: 6px 0; cursor: pointer; } .stop { background: #f8d7da; border-color: #f5c2c7; } .highlight { background: #ffe8cc; border-color: #ffa94d; } </style> </head> <body> <h2>jQuery prevUntil() – Highlight Previous Siblings Until a Target</h2> <p class="description"> Click any item to highlight all previous siblings <strong>up to but not including</strong> the red <kbd>.stop</kbd> item using <kbd>prevUntil('.stop')</kbd>. </p> <div class="container"> <div class="item">Step 1</div> <div class="item">Step 2</div> <div class="item stop">STOP HERE</div> <div class="item">Step 3</div> <div class="item">Step 4</div> <div class="item">Step 5</div> </div> <script> $(function () { $('.item').on('click', function () { $('.item').removeClass('highlight'); // Clear previous highlights $(this).prevUntil('.stop').addClass('highlight'); // Highlight previous siblings until '.stop' }); }); </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