jQuery closest exclude self

后端 未结 4 1076
余生分开走
余生分开走 2020-12-29 18:15

closest() will get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree. But I want

4条回答
  •  萌比男神i
    2020-12-29 19:01

    Vanilla js:

    el.parentElement.closest('.container')
    

    Jquery:

    el.parent().closest('.container');
    

提交回复
热议问题