parent vs closest

后端 未结 7 1312
终归单人心
终归单人心 2021-01-07 18:33

Why does this work:

$(\'.button_30\').click(function(){
    $(this).closest(\'.portlet\').find(\'.portlet_content\').text(\"foo\");
});​

an

7条回答
  •  遥遥无期
    2021-01-07 19:09

    The closest[API Ref] method traverses up the ancestor tree as far as it needs to go to find a selector match.

    The parent[API Ref] method only looks at the direct parent.

提交回复
热议问题