Assign ids to buttons

How can I add ids to the buttons which are created like the following in jQuery dialog. Here’s a code snippet and here is my complete code in JSFiddle


let buttons = {};

  buttons["Login next suggested value " + additionalValue] = function() {
    $(this).dialog("close");
  };

  buttons["Login case number of your choice"] = function() {
    $(this).dialog("close");
  };

  buttons["Cancel button"] = function() {
    $(this).dialog("close");
  };

I would like to have button id for first buttons as #suggestedValue, second button as #yourChoice and for the third button as #cancelChoice

I’m not super familiar with JQuery, but perhaps try

$(selector).attr('id', 'the-id-you-want-to-use')

You would need to change your code up somewhat to move away from the Object invocation of buttons to the Array invocation.

  let buttons = [
      {"text": "Login next suggested value " + additionalValue,
       "id": "suggestedValue",
       "click": function() { $(this).dialog("close"); }
      },
      ...
];
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.