11
<div id="grandfather">
  <div id="uncle"></div>
  <div id="father>
    <div id="me"></div>
  </div>
</div>

I am at $("#me") , and I want to select my uncle, using stuff like :

 $("#me").find("#uncle")
 $("#me").next("#uncle")
 $("#me").prev("#uncle")

How ?

Sampson
  • 265,109
  • 74
  • 539
  • 565
Ali Bassam
  • 9,691
  • 23
  • 67
  • 117
  • This question seems a little too arbitrary for a useful answer. I'd suggest just studying jQuery's [traversal methods](http://api.jquery.com/category/traversing/) unless you can provide more context. – jaredhoyt May 05 '12 at 06:22

3 Answers3

23

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.

Sampson
  • 265,109
  • 74
  • 539
  • 565
2
var uncle = $('#me').parent().prev();
rawb
  • 2,296
  • 18
  • 9
0
$(this).parent().prev().append("This is uncle");
robert
  • 33,242
  • 8
  • 53
  • 74
kongaraju
  • 9,344
  • 11
  • 55
  • 78