jQuery: selecting grandparents

后端 未结 6 1070
悲哀的现实
悲哀的现实 2020-12-14 05:39

Is there a better way to select grandparent elements in jQuery in order to avoid this ?

$(this).parent().parent().parent().parent().parent().children(\".titl         


        
6条回答
  •  旧巷少年郎
    2020-12-14 06:12

    Use the parents() selector to get all parents of an element. You can then either search the collection, or iterate over it if you want to affect all ancestors.

提交回复
热议问题