Home  >  Article  >  Web Front-end  >  Use jquery siblings to get all siblings (siblings) of an element

Use jquery siblings to get all siblings (siblings) of an element

巴扎黑
巴扎黑Original
2017-06-24 10:20:291775browse

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=&#39;button&#39;]").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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn