March 28, 2011

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

Question by Girish Chaudhari

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?

Answer by Jo-Herman Haugholt

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

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

Answer by Starx

I think you can do something like this.

$(window).load(function() {
    $("span[class=ui-button-text]:contains('OK')").each(function() {
          $(this).addClass("myClass");
    });
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!