jquery get father of element

后端 未结 6 2119
攒了一身酷
攒了一身酷 2020-12-21 06:08

I\'ve got an element which resides inside a div. I\'d like to get the div by the child\'s ID, is this possible? if so how?

Thank you!

6条回答
  •  一整个雨季
    2020-12-21 06:28

    Use the parent method of jQuery:

    $("#myChild").parent()
    

    You can even give it a selector if the parent element you're looking for is not the direct parent:

    $("#myChild").parent(".container")
    

    There's a slew of functions that help you traverse the DOM, and you can find detailed information in the jQuery reference.

提交回复
热议问题