So I currently have a jQuery dialog with two buttons: Save and Close. I create the dialog using the code below:
$dialogDiv.dialog({
autoOpen: false,
Select the div which has role dialog then get the appropriate buttons in it and set the CSS.
$("div[role=dialog] button:contains('Save')").css("color", "green");
$("div[role=dialog] button:contains('Cancel')").css("color", "red");
You should change the word "className" for "class"
buttons: [
{
text: "Cancel",
class: 'ui-state-default2',
click: function() {
$(this).dialog("close");
}
}
],
I’m reposting my answer to a similar question because no-one seems to have given it here and it’s much cleaner and neater:
Use the alternative buttons
property syntax:
$dialogDiv.dialog({
autoOpen: false,
modal: true,
width: 600,
resizable: false,
buttons: [
{
text: "Cancel",
"class": 'cancelButtonClass',
click: function() {
// Cancel code here
}
},
{
text: "Save",
"class": 'saveButtonClass',
click: function() {
// Save code here
}
}
],
close: function() {
// Close code here (incidentally, same as Cancel code)
}
});
I think there are two ways you can handle that:
When I look at the source with firebug for one of my dialogs, it turns up something like:
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<button class="ui-state-default ui-corner-all ui-state-focus" type="button">Send</button>
<button class="ui-state-default ui-corner-all" type="button">Cancel</button>
</div>
So I could for example address the Send button by adding some styles to .ui-state-focus (with perhaps some additional selectors to make sure I override jquery's styles).
By the way, I´d go for the second option in this case to avoid problems when the focus changes...