Which is more efficient: .parent().parent().parent() ~or~ parents(“.foo”) ~or~ closest(“.foo”)

前端 未结 7 1816
-上瘾入骨i
-上瘾入骨i 2020-12-15 03:06

I have an A tag which triggers the animation of it\'s great-great-great-grandparent. All of the following will work, but which is most efficient, and why?

$         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-15 03:55

    A quick test in Firefox 3.6.3 reveals that parents('.foo').eq(0) is actually significantly faster than closest('.foo'). It's debatable whether it is as maintainable, but it might prove to be more 'efficient' in specific scenarios.

提交回复
热议问题