jQuery Use siblings to get all siblings of an element of sibling element usage example


This article example shows how jQuery uses siblings to get all siblings of an element. Share it for your reference, as follows:

siblings () belongs to API of the jQuery filter class and is used to find all siblings (all siblings) of an element.

<div id="contentHolder">
  <input type="button" value="1" id="button1"></input>
  <input type="button" value="2" id="button2"></input>
  <input type="button" value="3" id="button3"></input>
</div>

If you need to implement the following functions: Click a button, the button background color changes to # 88b828, other buttons background color changes to # 15b494. At this time, siblings, API is very useful and simple.

$(function(){
  $("#contentHolder input[type='button']").click(function(){
    $(this).css("background","#88b828");
    $(this).siblings().css("background","#15b494");
  });
})

More readers interested in jQuery can check the topics of this site: “Summary of jQuery Page Element Operation Skills”, “Summary of jquery Selector Usage”, “Summary of jQuery Form Operation”, “Summary of jQuery Common Plug-ins and Usage”, “Summary of jQuery Form (table) Operation Skills”, “Summary of jQuery Extension Skills” and “Summary of jQuery Common Classic Special Effects”

I hope this article is helpful to everyone’s jQuery programming.