4

I am new in Jquery. I have a code for dialog.

$(this.choosePadsContainer).dialog({ 
        title: 'Choose pad locations',
        autoOpen: false,
        modal: true,
        buttons: { "OK": function () {
            //Extract all checked pad locations.
            var checkedPads;
            checkedPads = new Array();
            $(self.padLocationsForActivity + " input:checked").each(function (index, value) {
                checkedPads.push($(value).val());
            });
            //Set selected pad text.
            setSelectedPadText(self.selectedPadsLblIdFormat, $(self.hiddenActivityAreaCode).val(), checkedPads);
            $(this).dialog("close");
        }
        }
    });

I want to give css class to the OK button. How will it be done?

Starx
  • 77,474
  • 47
  • 185
  • 261
Girish Chaudhari
  • 1,607
  • 5
  • 16
  • 24

4 Answers4

9

Use the alternate (array) syntax for the buttons property:

$(this.choosePadsContainer).dialog({ 
    title: 'Choose pad locations',
    autoOpen: false,
    modal: true,
    buttons: [
        {
            text: 'OK',
            className: 'myClass',
            click: function () {
                //Extract all checked pad locations.
                var checkedPads;
                checkedPads = new Array();
                $(self.padLocationsForActivity + " input:checked").each(function (index, value) {
                    checkedPads.push($(value).val());
                });
                //Set selected pad text.
                setSelectedPadText(self.selectedPadsLblIdFormat, $(self.hiddenActivityAreaCode).val(), checkedPads);
                $(this).dialog("close");
            }
        }
    ]
});
Raphael Schweikert
  • 18,244
  • 6
  • 55
  • 75
2

As per tvanfosson's answer here, you can use the open handler:

open: function(event) {
    $('.ui-dialog-buttonpane').find('button:contains("OK")').addClass('okButton');
}

E.G.

$(this.choosePadsContainer).dialog({ 
    title: 'Choose pad locations',
    autoOpen: false,
    modal: true,
    open: function(event) {
        $('.ui-dialog-buttonpane').find('button:contains("OK")').addClass('okButton');
    },
    buttons: { "OK": function () {
        //Extract all checked pad locations.
        var checkedPads;
        checkedPads = new Array();
        $(self.padLocationsForActivity + " input:checked").each(function (index, value) {
            checkedPads.push($(value).val());
        });
        //Set selected pad text.
        setSelectedPadText(self.selectedPadsLblIdFormat, $(self.hiddenActivityAreaCode).val(), checkedPads);
        $(this).dialog("close");
    }
    }
});
Community
  • 1
  • 1
Scoobler
  • 9,696
  • 4
  • 36
  • 51
0

I think you can do something like this.

$(window).load(function() {
    $("span[class=ui-button-text]:contains('OK')").each(function() {
          $(this).addClass("myClass");
    });
});
Starx
  • 77,474
  • 47
  • 185
  • 261
0

AFAIK it's not directly supported, but something this should work:

$(".ui-dialog-buttonset .ui-button", this.choosePadsContainer).addClass("foo");

Jo-Herman Haugholt
  • 462
  • 1
  • 5
  • 15