How to reach the uncle using jquery

前端 未结 3 1267
感动是毒
感动是毒 2021-01-11 14:44
相关标签:
3条回答
  • 2021-01-11 15:08
    $(this).parent().prev().append("This is uncle");
    
    0 讨论(0)
  • 2021-01-11 15:26

    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.

    0 讨论(0)
  • 2021-01-11 15:33
    var uncle = $('#me').parent().prev();
    
    0 讨论(0)
提交回复
热议问题