Get Parent ID of this DIV

前端 未结 7 1272
野性不改
野性不改 2021-01-21 09:45

I am looking to find the parent div id (i.e. \"Bakerloo\") from this layout when the button is clicked within \".buttonleft0\" in jquery / javascript.

7条回答
  •  無奈伤痛
    2021-01-21 10:24

    alert($(this).parent().id);
    

    If you want to be sure to select correct class, try:

    alert($(this).parent('.div').id);
    

    If you have a deeper hierarchy you can use:

    alert($(this).parents('.div:eq(n)').id);
    

    where n is which parent you want to get

提交回复
热议问题