Skip to content Skip to sidebar Skip to footer

How To Reach The Uncle Using Jquery

I am at $('#me') , and I

Solution 1:

You could use $.parent and $.prev assuming your uncle is always above your father:

$(this).parent().prev(); // where 'this' is #me

You could also go all the way up to your grandfather, and find uncles from there:

$(this).parents("#grandfather").find(".uncles");

Or you could search your father's siblings:

$(this).parent().siblings("#uncle");

I would encourage you to read the Traversing portion of the jQuery API for various other methods.

Solution 2:

var uncle = $('#me').parent().prev();

Solution 3:

$(this).parent().prev().append("This is uncle");

Post a Comment for "How To Reach The Uncle Using Jquery"