Argiropoulos Stavros
Argiropoulos Stavros

Reputation: 9533

jQuery ancestors

Is there an easier way to say

$('element').parent('parentElement').parent('grandParentElement'); 

Answer: Try parents() or closest()

Upvotes: 4

Views: 1785

Answers (3)

Argiropoulos Stavros
Argiropoulos Stavros

Reputation: 9533

$('element').parents('grandParentElement');

Notice "parents" and not "parent"

Upvotes: 0

Šime Vidas
Šime Vidas

Reputation: 186083

$('element').closest('grandParentElement');

Upvotes: 14

Quentin
Quentin

Reputation: 944431

$('element').parent().parent(); 

Upvotes: 4

Related Questions