jquerychild>;家长>;小孩

jquerychild>;家长>;小孩,jquery,css,selector,parent,Jquery,Css,Selector,Parent,我有以下html代码: <div class="im"> <div style="height:220px">HELLO WORLD! <a class="close">X</a> <a class="open" style="display:none;">V</a> </div> </div> <div class="im"> <div style="height:220px"&

我有以下html代码:

<div class="im">
<div style="height:220px">HELLO WORLD!
<a class="close">X</a>
<a class="open" style="display:none;">V</a>
</div>
</div>

<div class="im">
<div style="height:220px">HELLO WORLD!
<a class="close">X</a>
<a class="open" style="display:none;">V</a>
</div>
</div>
如何仅隐藏和显示V中的一个,它是父div的子级,它是X(class.close)的父级。

而不是此:

// This code unhides ALL Vs because $('.open') selects ALL anchors with the class
$('.open').show('fast');} //unhide V 
使用以下命令:

// This code unhides only the V you want because it selects only one anchor:
// the one which is next to the clicked element $(this) in your HTML.
$(this).siblings('.open').show('fast');} //unhide V 

“取消隐藏X”行也应进行相同的更改。

由于
X
V
是同级,因此可以使用适当命名的方法:


谢谢,我不知道兄弟姐妹()方法
// This code unhides only the V you want because it selects only one anchor:
// the one which is next to the clicked element $(this) in your HTML.
$(this).siblings('.open').show('fast');} //unhide V 
$(".close").click(function() {
    $(this).parent().css("height", "20px")
           .end().hide("fast")
           .siblings(".open").show("fast");
});

$(".open").click(function() {
    $(this).parent().css("height", "220px")
           .end().hide("fast")
           .siblings(".close").show("fast");
});