jQuery: How to get to a particular child of a parent?

后端 未结 5 394
迷失自我
迷失自我 2020-12-04 09:23

To give a simplified example, I\'ve got the following block repeated on the page lots of times (it\'s dynamically generated):

&l
5条回答
  •  伪装坚强ぢ
    2020-12-04 10:01

    Calling .parents(".box .something1") will return all parent elements that match the selector .box .something. In other words, it will return parent elements that are .something1 and are inside of .box.

    You need to get the children of the closest parent, like this:

    $(this).closest('.box').children('.something1')
    

    This code calls .closest to get the innermost parent matching a selector, then calls .children on that parent element to find the uncle you're looking for.

提交回复
热议问题