Tim Wilkinson
Tim Wilkinson

Reputation: 3791

jQuery select children of children of children etc

How do you target the children of children indefinately in jQuery. I can find the first level children using .children() but can't go any deeper than that.

$('[data-snap-ignore="true"]').children().attr('data-snap-ignore', true);

I am basically having to find an element with attribute data-snap-ignore="true" and add that attribute to every child, grandchild, great grandchild and so on and so forth.

Upvotes: 0

Views: 65

Answers (3)

Praveen
Praveen

Reputation: 56539

Try this

var ch = $('[data-snap-ignore="true"]').children(); //returns all children
$.each(ch, function (i, j) {
    $(j).attr('data-snap-ignore', true);
});

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388446

Use .find('*')

$('[data-snap-ignore="true"]').find('*').attr('data-snap-ignore', true);

Upvotes: 1

Ankit Tyagi
Ankit Tyagi

Reputation: 2375

Try this way : this will find all children's having attribute 'data-snap-ignore'

Further Reading : .find()

$('[data-snap-ignore="true"]').find('[data-snap-ignore]');

Upvotes: 1

Related Questions