Javascript examples for jQuery Method and Property:prevUntil
Get previous sibling element for li element between a DOM object and a class selector
<!DOCTYPE html> <html> <head> <style> .siblings * {//w w w . j a v a 2 s . com display: block; border: 2px solid lightgrey; color: lightgrey; padding: 5px; margin: 15px; } </style> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ var DOM = document.getElementsByClassName("li.stop"); $("li.start").prevUntil(DOM,".first").css({"color": "red", "border": "2px solid red"}); }); </script> </head> <body> <div style="width:500px;" class="siblings"> <ul>ul (parent) <li class="stop">li</li> <li class="first">li</li> <li>li</li> <li class="first">li</li> <li class="start">li</li> <li>li</li> <li>li</li> </ul> </div> </body> </html>