What\'s the difference between these? Is one more efficient than the other? I\'m a little bit confused to why they both exist. Say I have this markup:
3条回答 一整个雨季 (楼主) 2021-02-13 13:34 .parent() only goes up one level, while closest() includes the current element, and all parents. Example (selecting from the bottom div, x = matched elements): parent() parent('body') .closest('div') .parents('div') body div x div x x this--> div x 0 讨论(0) 查看其它3个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复 热议问题
.parent() only goes up one level, while closest() includes the current element, and all parents.
.parent()
closest()
Example (selecting from the bottom div, x = matched elements):
div
x
parent() parent('body') .closest('div') .parents('div') body div x div x x this--> div x