Find parent and first child of it's parent

前端 未结 4 1269
無奈伤痛
無奈伤痛 2021-02-19 23:44

I am trying to find the parent of an element and it\'s parent first child, the code is like this:

        
  • &l
4条回答
  •  故里飘歌
    2021-02-20 00:10

    There is no need of total traversing back to the parent one after the other in a hierarchy, you can just do use parents() instead of parent() in this way

    $('.selected').parents('ul.lowerMenu').children(:first-child').addClass('selected');
    

    Try it this is working!!

提交回复
热议问题