How to reach the uncle using jquery

前端 未结 3 1283
感动是毒
感动是毒 2021-01-11 14:44
3条回答
  •  独厮守ぢ
    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.

提交回复
热议问题