siblings() belongs to the API filter class of jquery, used to find all sibling elements (all siblings) of an element.
<p 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> </p>
If you need to implement the following functions: when you click a button, the background color of the button becomes #88b828, and the background color of other buttons becomes #15b494. At this time, the siblings API is very useful and simple.
$(function(){ $("#contentHolder input[type='button']").click(function(){ $(this).css("background","#88b828"); $(this).siblings().css("background","#15b494"); }); })
The above is the detailed content of Use jquery siblings to get all siblings (siblings) of an element. For more information, please follow other related articles on the PHP Chinese website!