Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add id in jquery?

I have created one dialog box in jquery. and there is one button called 'save'. I need to add one id to this save buttton. How can I achive in this in jquery. This is my code

$(function() {
    $( "#dialog" ).dialog({

         height: 400,
      width: 650,
      modal: true,
      buttons: {

        Save: function() {
          dialog.dialog( "close" );
        }
      },
      close: function() {
        form[ 0 ].reset();
        allFields.removeClass( "ui-state-error" );
      }

    });
});
like image 395
jumban Avatar asked Jun 01 '26 04:06

jumban


2 Answers

The Save function has a parameter event which has a target that is the DOM element of the button, then you can set the id inside of the function like this:

Save: function(event) {
   $(event.target).attr('id', 'your-id');
}

The specification about the buttons property says:

Specifies which buttons should be displayed on the dialog. The context of the callback is the dialog element; if you need access to the button, it is available as the target of the event object.

like image 51
ScientiaEtVeritas Avatar answered Jun 03 '26 18:06

ScientiaEtVeritas


This is the most simplest

$(selector).attr('id', 'TheID');
like image 36
Rush.2707 Avatar answered Jun 03 '26 16:06

Rush.2707



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!