Which is more efficient: .parent().parent().parent() ~or~ parents(“.foo”) ~or~ closest(“.foo”)
Here’s an analyzation: parent() walks just one level up in the DOM tree. parents(“.foo”) walks up to the root and selects only those elements that match the given selector .foo. closest(“.foo”) walks up to the root but stops once an element matches the selector .foo. So I would choose the last one, closest(“.foo”). The reason: … Read more