jQuery getting ID of clicked link

前端 未结 6 2038
醉话见心
醉话见心 2020-12-18 10:22

I have a modal box in jQuery which I have created to display some embed code. I want the script to take the id of the link that is clicked but I can\'t

6条回答
  •  悲哀的现实
    2020-12-18 11:17

    The other answers are trying to fix the click() function, but your issue is actually with the generateCode function.

    You need to pass the clicked element to the generateCode function:

    $('.openembed').click(function () {
        generateCode(this);
    

    And modify generateCode:

    function generateCode(element) {
        var answerid = element.id;
    

    Of course var answerid = $('.openembed').attr('id'); within the click code isn't correct either, but it doesn't seem to do anything anyway.

提交回复
热议问题