Selector for grandchildren, or how to anchor the selector on a known element

Description of your first forum.
Surovi
Posts: 5
Joined: Mon Mar 14, 2016 10:17 am

Selector for grandchildren, or how to anchor the selector on a known element

Postby Surovi » Mon Mar 14, 2016 12:17 pm

Let's say I have a hierarchy of elements, with #root at its root. I can use $('#root > * > *') to get all its grandchildren. Is there any way I could do that if I already have $('#root')?

$('#root').find('* > *') is definitely not it, as it will happily "start" from any descendant for the first star, not just #root children.

Is there any function in jQuery that would "anchor" at the current element, starting with its children or itself? It's been bugging me for a while, and I couldn't find anything similar in the docs.

Saima Akter
Posts: 4
Joined: Mon Mar 14, 2016 9:54 am

Re: Selector for grandchildren, or how to anchor the selector on a known element

Postby Saima Akter » Mon Mar 14, 2016 12:19 pm

.find() is possibly the single most annoying jQuery traversal method, ever.
Thanks


Return to “Web Development”

Who is online

Users browsing this forum: No registered users and 1 guest