parent vs closest

后端 未结 7 1322
终归单人心
终归单人心 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 18:57

    parent() only looks one level up, you can try parents() to search all way up

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

    you can see the documentation

提交回复
热议问题