jQuery prevUntil() with stop and three types of filter elements

Description

jQuery prevUntil() with stop and three types of filter elements

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.siblings * {//from ww  w .ja v  a 2  s.co  m
  display: block;
  border: 2px solid lightgrey;
  color: lightgrey;
  padding: 5px;
  margin: 15px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("h2").prevUntil("h5", ".first, .second, .third")
     .css({"color": "red", "border": "2px solid red"});
});
</script>
</head>
<body>

<div style="width:500px;" class="siblings">
  <div>parent
    <h5>h5</h5>
    <h3 class="third">h3 class "third"</h3>
    <span>span</span>
        <h5>h5</h5>
    <span class="second">span also class "second"</span>
        <h5>h5</h5>
    <span class="second">span class "second"</span>
    <p>p</p>
        <h5>h5</h5>
    <p class="first">p class "first"</p>
    <p>p</p>
        <h5>h5</h5>
    <h3>h3</h3>
    <h2>h2</h2>
        <h5>h5</h5>
    <span>span</span>
    <p>p</p>
  </div>
</div>

</body>
</html>



PreviousNext

Related