Javascript parentsUntil()是最好的函数吗?滑动分页
给定html:Javascript parentsUntil()是最好的函数吗?滑动分页,javascript,jquery,Javascript,Jquery,给定html: <div class="a"> <div class="b"> <div class="c"> <div class="d"> </div> </div> <div class="d"> </div> <
<div class="a">
<div class="b">
<div class="c">
<div class="d">
</div>
</div>
<div class="d">
</div>
</div>
</div>
您可以$(this).closest('.a')
您还可以执行以下操作:
$(".d").click(function() {
// parents() will walk up through parent nodes. If you
// pass a selector, the set will be filtered. If not,
// you get the full list of parent elements.
var elementA = $(this).parents(".a");
});
医生
希望有帮助!干杯
$(".d").click(function() {
// parents() will walk up through parent nodes. If you
// pass a selector, the set will be filtered. If not,
// you get the full list of parent elements.
var elementA = $(this).parents(".a");
});