【发布时间】:2015-06-23 17:01:41
【问题描述】:
大家下午好,我正在尝试在 div 中选择一个特定的同级。我尝试过使用我发现的许多不同的建议,但似乎都无法奏效。使用this,看起来我可以使用这样的东西:
$( "#prev ~ div" ).css( "border", "3px groove blue" );
但是,我想在选择器中使用 (this),可能是这样:
&(this " ~ p").show();
基本上,我只是想在触发某个事件时显示一个段落兄弟。如果有人有更好的方法,我很乐意接受建议。我尝试过其他方法,例如使用 next() 和兄弟姐妹("p") 但似乎无法让它工作。这是我目前拥有的html和jquery的一部分。
<div class="col-sm-8 items">
<div class="item">
<h6>Dynamic Web Programming<h6>
<img src="DynamicWebProgramming.jpg">
<p>This book is a great tool for learning to develop Dynamic Web Pages.</p>
// This is the paragraph that is hidden and I want to show on mouseover
</div>
</div>
$(document).ready(function() {
$(".item p").hide();
$(".item h6").mouseover(function() {
$(this).addClass("mouseover");
$(this).siblings().addClass("mouseover");
$(this).siblings("p").show(); // This is where I want to call .show() for the
specific sibling
})
$(".item p").click(function() {
$(this).removeClass("mouseover");
$(this).siblings().removeClass("mouseover");
})
})
如果有人能提供任何建议,那就太好了! 谢谢, 安迪
【问题讨论】: