Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript parentsUntil()是最好的函数吗?滑动分页_Javascript_Jquery - Fatal编程技术网

Javascript parentsUntil()是最好的函数吗?滑动分页

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> <

给定html:

     <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");
});