parent vs closest

后端 未结 7 1263
终归单人心
终归单人心 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:12

    • .parent() only looks at the immediate ancestor.

    • .closest() looks at all ancestors, as well as the originating element, and returns the first match.

    • .parents() looks at all ancestors, and returns all matches.

提交回复
热议问题