Get Parent ID of this DIV

前端 未结 7 1190
野性不改
野性不改 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:35

    The parent() function returns the jQuery object, so you need to use the attr() for any of it's attributes like so:

    $(this).closest().attr('id');
    

    Edit: On further inspection it appears the button isn't the direct child of the div, and so use of the closest() function would be required.

提交回复
热议问题