Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give css class to the OK button of dialog in JQuery?

Tags:

jquery

css

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?

like image 939
Girish Chaudhari Avatar asked Dec 21 '22 16:12

Girish Chaudhari


2 Answers

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");
            }
        }
    ]
});
like image 52
Raphael Schweikert Avatar answered Feb 19 '23 07:02

Raphael Schweikert


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");
    }
    }
});
like image 22
Scoobler Avatar answered Feb 19 '23 07:02

Scoobler