JQuery: Get the parent element id of a clicked element

后端 未结 4 418
鱼传尺愫
鱼传尺愫 2021-01-18 01:38

I have a div like this:

x
4条回答
  •  臣服心动
    2021-01-18 01:40

    This works fine:

    $('a.popupCloseClass').click(function() {
        var id = $(this).parent().attr('id');
    });​
    

    JSFiddle Demo

    You should just use this instead of the way you are getting the ID and then trying to use it as a selector (you were missing the # before the ID):

提交回复
热议问题