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

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

巴扎黑
Release: 2017-06-24 10:20:29
Original
1818 people have browsed it

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>
Copy after login


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");
	});
	
})
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template