How to find first parent element in jquery

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

Conside below html -

3条回答
  •  别跟我提以往
    2021-02-14 06:13

    just use

    $(".element").closest('#container1');
    

    if no ancestor with that id is found then

    $(".element").closest('#container1').length will be 0

提交回复
热议问题