Answer the question
In order to leave comments, you need to log in
jQuery parents().get(2) vs parent().parent().parent()?
Help me figure out which method is better and faster
Answer the question
In order to leave comments, you need to log in
As for the speed, I won’t say, purely visually I would choose the first option out of the two proposed.
And ideally, I would use a selector in the parents call
el.parents('.container')
el.parents('li')
the question concerns only the aesthetics of the code and speed.
is it correct to repeat parent() 3 times or is it better to get the result with a single call to parents().
the question can be reformulated for the 5th parent case:
parents().get(5) vs. parent().parent().parent().parent().parent()
Actually, the question itself appeared when analyzing the code of the Indians, a variant with the repetition of parent () is very common. And moreover, they can repeat more than 10 times.
At first I condemned this approach. But apparently their approach has the right to life.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question