<p class="select">father的大哥或大姐</p>
<div id="father">father
<p id="john">john</p>
<p id="joy">joy (john的弟弟或妹妹)</p>
</div>
<p class="select" id="first">father的大弟或大妹</p>
<p class="select">father的二弟或二妹</p>
#father + .select {
background-color: orange;
}
/* 分辨各tag層級 */
div {
border:black 3px solid;
}
div > * {
margin-left: 10px;
}
xxxxxxxxxx
$("#father + .select").click(function() {
alert("click");
});
// jquery 可以使用.next() 來抓同層後的第一個元素
$("#john").next().click(function () {
alert(".next()");
});
// 指定同層後的第一個元素 (當father的二弟或二妹class沒有select時,不會被選取到)
$("#first").next(".select").click(function () {
alert(".next('.select')");
});
This Pen doesn't use any external CSS resources.