gpt4 book ai didi

javascript - 如何在父div中选择子div

转载 作者:行者123 更新时间:2023-11-28 15:59:51 24 4
gpt4 key购买 nike

当我点击replyBtn时,我想选择“postHandel”类的html。有多个“转发”div,我想要我在其中单击replyBtn 的当前div 的postHandel。

<div class="repost" data-id="52">
<div class="profileImg"></div>
<div class="postWrap">
<div class="postUser">Tejas Kulkarni</div>
<div class="postHandel">@tejas</div>
<div class="postText"> </div>
</div>
<a href="#" class="expandRP pull-right expandRP52" data-id="52"><i class="icon-chevron-down"></i></a>
<div class="clearfix"></div>

<div class="postOptions twtOptRP52">
<ul>
<li> <a class="btn btn-mini rtBtn" data-id="96"><i class="icon-retweet"></i> Repost</a></li>
<li> <a class="btn btn-mini replyBtn" data-id="96"><i class="icon-reply"></i> Reply</a></li>
<li> <a class="btn btn-mini favBtn" data-id="96"><i class="icon-star"></i> Fav</a></li>
<li><div class="loadingPostsBtn hideme loadingBtn-96 hideme"><img src="http://linkzone.dev/assets/img/ajax-loader.gif"></div></li>
<li><div class="loadingFailBtn hideme loadingFail-96 hideme"><img src="http://linkzone.dev/assets/img/ajax-fail.gif"></div></li>
</ul>
</div>

我的 jQuery 代码是:

 $(document).on("click",".replyBtn",function(){

var postHandel = $(this).closest(".postWrap").html('');
var log = $(postHandel).closest(".postHandel").html();
console.log(log);

});

最佳答案

试试这个:

var log = $(this).closest(".repost").find(".postHandel:first").html();

关于javascript - 如何在父div中选择子div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17343824/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com