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 0 讨论(0) 查看其它3个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复 热议问题
just use
$(".element").closest('#container1');
if no ancestor with that id is found then
id
$(".element").closest('#container1').length will be 0
$(".element").closest('#container1').length
0