parent vs closest

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

    Because in the second selector you're looking for the Parent and this function move's into the DOM to the node father but only one level which contains the class portlet_footer portlet_footer_30 not the classes that you're passing to the selector .portlet to work with parent you should move two levels in other words.

    each time that you're using parent you move one node up

提交回复
热议问题