0

How do I go about adding styles to jquery buttons on a dialog? I want to color some one color and others another color.

I've tried using the class: but i didnt seem to get too much effect. am i doing something wrong? do i need to use something else? do i need to place something somewhere else?

code:

function DisplayCommonDialog(url, title, height, width) {
    HideDialogs();
    var dialogButtons = [{
        text: "Save",
        click: function () {
                    ...
                }
            }
        },
        width: '70px'
    }, {
        text: "Cancel",
        click: function () {
            $(this).dialog("close");
        }
    }];
    if (title.indexOf("Delete") >= 0) {
        dialogButtons = [{
            text: "OK",
            click: function () {
                ...
            },
            width: '70px'
        }, {
            text: "Cancel",
            click: function () {
                $(this).dialog("close");
            }
        }];
    }
if (popUpDialog != null) {
        $("#").dialog("option", {
            width: width,
            height: height,
            title: title,
            open: function () {
                ...
            },
            close: function () {
                ...
            },
            buttons: dialogButtons

        });
        ...
    }
    else {
        popUpDialog = $("#").dialog({
            width: width,
            height: height,
            autoResize: true,
            modal: true,
            title: title,
            open: function () {
                ...
            },
            close: function () { 
                ...
            },
            overlay:
            {
                opacity: 0.5,
                background: "black"
            },
            position: ['center', 'center'],
            buttons: dialogButtons
        });
    }
}
1

3 Answers 3

5

to add css class in dialog buttons, just use the button button property "class" :

$("#").dialog({
    buttons: [{
        "text":'your button name',
        "click": $.noop,
        "class": 'your-css-class1 your-css-class2'
    }]
})

the property "class" in each declared button will be inserted when creating dialog.

Hope this help.

similare question about button style in dialog available here

Sign up to request clarification or add additional context in comments.

1 Comment

That's true. I confess this solution for me is like a side effect because it is not really explain in documentation and is just the result that when creating button in dialog widget, all given properties will be added to the button itself before calling .button() on it. But the code is easier to read too.
0

http://jqueryui.com/themeroller/

or

How to style different hover colors for jquery dialog buttons

or how to change jquery dialog buttons

Comments

-1

findout the CSS class being applied to the button using firebug and then override it in your css

2 Comments

Not anymore, now we know to use either theme roller or give the classes in the buttons object. That way they can even change the classnames and it will still work
@mplungjan : if you are doing it thru javascript you are reapplying a class once the element is loaded with its default css. i think overriding the default style in our css is much easier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.