jQuery closest exclude self

后端 未结 4 1072
余生分开走
余生分开走 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条回答
  •  情话喂你
    2020-12-29 19:09

    If you truly want only parent divs, then yes $(this).parents('.container') would work. If you want to look for the closest element and allow for it to be a sibling (which it seems might be what you are actually trying to accomplish) you can use $(this).prev('.container').

提交回复
热议问题