jQuery: selecting grandparents

后端 未结 6 1087
悲哀的现实
悲哀的现实 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:17

    You can use the parents() method which matches parents against a selector

    http://api.jquery.com/parents/

    Or if you're using 1.4 there is a new parentsUntil() method

    http://api.jquery.com/parentsUntil/

提交回复
热议问题