我有一个包装 div,里面有一个按钮和一个隐藏的 div。按下按钮时,应显示 div。我不想使用 id,因为该结构在网页上多次出现。什么是正确的 jquery 命令?
HTML
<div class="wrap">
<div class="button"> see more </div>
<div class="moreInfos"> Lorem ipsum... </div>
</div>
CSS
.moreInfos{ display: none;}
jQuery
$(".wrapp").on('click', '.button', function(){
$(this).parent('.moreInfos').css('display', 'block');
});
最佳答案
如果点击事件绑定(bind)到按钮上:
$(this).parent().find(".moreInfos").show();
如果点击事件绑定(bind)到包装 div:
$(this).find(".moreInfos").show();
关于javascript - jQuery - 通过父级按类获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19908230/