function ClickParent(ClickElem,ElemFind)
{
$("."+ClickElem).click(function() {
var GetGrp = $(this).parents(".group");
GetGrp.find("."+ElemFind).fadeToggle();
});
}
// Find one level
ClickParent('name','moreinfo');
// Find another level
ClickParent('moreinfo','evenmore');

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="group">
I am
<a href="#" class="name" style="color:black;">How are you?</a>
<div class="moreinfo" style="display: none;">
Fine
</div>
<div class="evenmore" style="display: none;">
Even more stuff.
</div>
</div>
&#13;
如何在没有空格的情况下显示组类旁边的moreinfo类的内容。如果有更多内容,那么它们就像pass一样显示。如何实现呢?
答案 0 :(得分:1)
问题是div
是一个块元素,所以请尝试跨度
function ClickParent(ClickElem, ElemFind) {
$("." + ClickElem).click(function() {
var GetGrp = $(this).parents(".group");
GetGrp.find("." + ElemFind).fadeToggle();
});
}
// Find one level
ClickParent('name', 'moreinfo');
// Find another level
ClickParent('moreinfo', 'evenmore');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="group">
I am
<a href="#" class="name" style="color:black;">How are you?</a>
<span class="moreinfo" style="display: none;">
Fine
</span>
<span class="evenmore" style="display: none;">
Even more stuff.
</span>
</div>