How to find first parent element in jquery

前端 未结 3 751
情歌与酒
情歌与酒 2021-02-14 05:33

Conside below html -

3条回答
  •  清酒与你
    2021-02-14 06:16

    $(".element").parents();
    

    will give all parents of .element(including html and body)

    DEMO

    To find any specific parent, suppose container1 then

    $('.element').parents('.container1')
    

    DEMO

    jQuery .parents() generally find all parents, but if you passed a selector then it will search for that.

提交回复
热议问题