Search code examples
jqueryjquery-dialog

Get the id of the button which opens the dialog


I have a button inside each row of a table generated inside a loop.The button has class click_link.The id will be different for each row. On clicking the button, a jquery dialog is created.I need the id of the button inside click() of dialog buttons,ie click event of Edit button

$("#dialog_loader").dialog({resizable: false,
  height:"auto",
  modal: true,
  minWidth: 500,
  autoOpen:false,
  buttons: {
    "Edit": function() {
      $.ajax({
            url:url1,
            type:'POST',
            data:data1,
            success:function(msg){
               if(msg)
               {
                  //alert(msg);
                 //Here I need to get the id of the button which creates 
               the dialog.That is id of the button with class **click_link**
               } 
            }
        });
    },
    Cancel: function() {
      $( this ).dialog( "close" );
    }
  }
});

//click event of button
$(document).on('click','.click_link',function(){
    $("#dialog_loader").css({'display':'show'});
    $('#dialog_loader').dialog('open');
});

Solution

  • Set data() property to the id of dialog-box

    $('#dialog_loader').data('dialog_opener',"id of the button which create dialog").dialog('open');
    

    Then call the $("#dialog_loader").data("id of the button which create dialog") where it is needed