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 9203597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:30:29+00:00 2026-06-17T23:30:29+00:00

I have a function which creates a dialog filled with buttons, whose names come

  • 0

I have a function which creates a dialog filled with buttons, whose names come from a button array. See this post here.

What I would like to do is modify this function such that I can apply styles to the button array generated. As such…

function setAutoDialog(){
    var testArray = ["T1", "T2"];

    var testFunction = function () {
        alert("worked");
    }

    var myButtons = {};

    for(var i = 0; i < testArray.length; i++){
        myButtons[testArray[i]] = testFunction;
    }
    for(var i = 0; i < testArray.length; i++){
        myButtons[i].css('background','black');
    }

    $('#autoDialog').dialog({
        autoOpen: false,
        width: 'auto',
        buttons : myButtons
    }); 
}

As some of you might suggest, I just can’t apply a class to the button because the colors will be set by the user, or come from an array of ordered colors to match said button. Any help with this would be much appreciated.

  • 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-06-17T23:30:30+00:00Added an answer on June 17, 2026 at 11:30 pm

    You are going to have to fudge this just a bit.

    With this markup:

    <div id="autoDialog">howdy</div>
    

    you could create an array of colors and class names and then apply those:

    I have altered your procedure just a bit, and added some alerts so you see the class has been added: (this is a jQuery 1.9 version tested for the alert of the class property) – basically I create a dynamic style element and apply it. I add just enough to the style to override the existing style – sure its a hack but should work.
    example in practice: http://jsfiddle.net/Q4qT3/1/

    function setAutoDialog() {
        var testArray = ["T1", "T2"];
        var myClass = [{
            myclass: "primary",
            color: "#558899"
        }, {
            myclass: "secondary",
            color: "pink"
        }];
        var testFunction = function (e) {
            alert("worked2");
            alert($(e.target).prop("class"));
        };
    
        var myButtons = [];
        var i = 0;
        for (i = 0; i < testArray.length; i++) {
            myButtons[i] = {
                text: testArray[i],
                click: testFunction,
                myclass: myClass[i].myclass
            };
        }
        var myStyle = "<style type='text/css'> ";
        for (i = 0; i < testArray.length; i++) {
            myStyle += " .ui-dialog-buttonset ." ;
            myStyle += myClass[i].myclass;
            myStyle += " span.ui-button-text {background:";
            myStyle += myClass[i].color + ";}";
        }
        myStyle += "< /style > ";
        $(myStyle).appendTo("head");
    
        $('#autoDialog').dialog({
            autoOpen: false,
            width: 'auto',
            buttons: myButtons,
            create: function (event, ui) {
                //         Get the dialog
                var dialog = $(event.target).parents(".ui-dialog.ui-widget");
                var buttons = dialog.find(".ui-dialog-buttonpane").find("button");
                for (var i = 0; i < buttons.length; i++) {
                    $(buttons[i]).addClass($(buttons[i]).attr("myclass"));
                }
            }
        });
        $('#autoDialog').dialog("open");
    }
    setAutoDialog();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function which creates an object of values, but im getting this
I have a button which creates form elements on click . My addelement function
I currently have a jQuery function which onclick opens a dialog box. This allows
I have the following function which creates a std::vector of iterators into another container:
I have a gtk widget (from gtk_dialog_new()) which was created in a different function
i have a js function which gets html to create new employee from controller,
I have function some_func_1 which will create an object of type some_type and will
I have created a function which gets an encoded string (possibly UTF-16 not sure)
I have created an utility function which I include in almost all Javascript code
I have created a JS function which executes fine when it's included an the

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.