<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Selecting All the Preceding Sibling Elements in jQuery</title> <style> .highlight{ background: pink; } </style> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("ul").prevAll().addClass("highlight"); }); </script> </head> <body> <div class="container"> <h1>Happy Morning</h1> <p>Here is an<em> uncomplicated paragraph</em>.</p> <p>This constitutes an additional paragraph.</p> <ul> <li>List One</li> <li>List Two</li> </ul> </div> </body> </html>