jQuery – Next Siblings Selector (“prev ~ siblings”)

The jQuery next siblings selector selects all sibling elements that follow after the “prev” element, have the same parent, and match the filtering “siblings” selector.

Source Code

<!DOCTYPE html>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
<h4>Text 1</h4>
<h5>Text 2</h5>
<h6>Text 3</h6>
<h5>Text 4</h5>
<button>Click Here</button>

jQuery("button").click(function () {
	jQuery("h4 ~ h5").css({border:"3px #1E8CBE solid"});


Following example finds all h5 that are siblings after h4.

Text 1

Text 2
Text 3
Text 4


No comments yet.

Leave a Reply