jquery traversing to find a parent's parent

前端 未结 7 662
谎友^
谎友^ 2021-01-14 08:58

HTML:

  • 7条回答
    •  春和景丽
      2021-01-14 10:00

      You should use closest() which will traverse up the DOM until it finds the element you're after:

      $('a').closest('li');
      

      If you were doing this the other way around (i.e. you had the li and wanted to find the a) you would use:

      $('li').find('a');
      

    提交回复
  • 热议问题