Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

jQuery - Siblings

<!DOCTYPE html>
<html>
<head>
<style>
.siblings * { 
  display: block;
  border: 2px solid lightgrey;
  color: lightgrey;
  padding: 5px;
  margin: 15px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#button1").click(function(){
    $("h2").siblings("").css({"color": "red", "border": "2px solid red"});
  }); 
  $("#button2").click(function(){
    $("h2").siblings("p").css({"color": "red", "border": "2px solid red"});
  }); 
  $("#button3").click(function(){
    $("h2").next().css({"color": "red", "border": "2px solid red"});
  }); 
  $("#button4").click(function(){
    $("h2").nextAll().css({"color": "red", "border": "2px solid red"});
  }); 
  $("#button5").click(function(){
    $("h2").nextUntil("h6").css({"color": "red", "border": "2px solid red"});
  });   
});
</script>
</head>
<body>
<button id="button1">siblins</button>
<button id="button2">siblins(p)</button>
<button id="button3">siblins(next)</button>
<button id="button4">siblins(nextAll)</button>
<button id="button5">siblins(nextUntil)</button>
<div class="siblings">
<div>div (parent)
  <p>p</p>
  <span>span</span>
  <h2>h2</h2>
  <h3>h3</h3>
  <h4>h4</h4>
  <h5>h5</h5>
  <h6>h6</h6>  
  <p>p</p>
</div>
</div>
</body>
</html>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.