Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4115972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:39:02+00:00 2026-05-20T22:39:02+00:00

So I currently have a jQuery dialog with two buttons: Save and Close. I

  • 0

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,
    modal: true,
    width: 600,
    resizable: false,
    buttons: {
        Cancel: function() {
                        // Cancel code here
        },
        'Save': function() {
                        // Save code here
        }
    },
    close: function() {
        // Close code here (incidentally, same as Cancel code)
    }
});

However, both buttons are the same color when this code is used. I’d like my Cancel button to be a different color than my Save. Is there a way to do this using some built in jQuery options? I didn’t get much help from the documentation.

Note that the Cancel button I’m creating is a pre-defined type, but ‘Save’ I’m defining myself. Not sure if that will have any bearing on the issue.

Any help would be appreciated. Thanks.

UPDATE: Consensus was that there were two roads to travel here:

  1. Inspect the HTML using a Firefox
    plugin like firebug, and note
    the CSS classes that jQuery is
    applying to the buttons, and take a
    stab at overriding them. Note: in
    my HTML, both buttons were used the
    exact same CSS classes and no unique
    IDs, so this option was out.
  2. Use a jQuery selector on dialog open
    to catch the button that I wanted,
    and add a CSS class to it then.

I went with the second option, and used the jQuery find() method as I think this is more appropriate than using :first or :first-child b/c the button that I wanted to change wasn’t necessarily the first button listed in the markup. Using find, I can just specify the name of the button, and add CSS that way. The code I ended up with is below:

$dialogDiv.dialog({
    autoOpen: false,
    modal: true,
    width: 600,
    resizable: false,
    buttons: {
        Cancel: function() {
                        // Cancel code here
        },
        'Save': function() {
                        // Save code here
        }
    },
        open: function() {
            $('.ui-dialog-buttonpane').find('button:contains("Cancel")').addClass('cancelButtonClass');
        }
    close: function() {
        // Close code here (incidentally, same as Cancel code)
    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:39:02+00:00Added an answer on May 20, 2026 at 10:39 pm

    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)
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'have a dialog box in JQuery that have two buttons. When the button Upload
Is there a better way to do this jquery code? Currently I have to
I am creating my own carousel slideshow for images, using Jquery. Currently i have
I am using jquery jqModal script for TWO popup windows: <div id=dialog></div> // load
I have jQuery validation working pretty well using a dialog for the error messages.
I have this code to popup a JQuery dialog box: $( #dialogBox ).dialog({ height:
I have a jQuery Dialog set to autoOpen:true . Thus it pops up on
I have jQuery draggable set up and working ok on a table row. Currently
I have a full Jquery Mobile app the currently builds and looks fine in
I have a problem with my jquery UI tabs currently only in Firefox 3.6.24

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.