1

I am forming some morel pop up at run time like below, but i want to apply the background color css how to apply it?

$("<div></div>")
                .addClass("dialog1")
                .attr("id", $(this).attr("id"))
                .appendTo("body")
               // .addCss("background-color","red")
                .dialog({
                    title: $(this).attr("data-dialog-title"),
                    close: function () { $(this).remove() },
                    width: $(this).attr("data-dialog-width"),
                    modal: true,
                    position: 'center',
                    resizable: $(this).attr("data-dialog-resizable")
                }).load(url);

                $(".close").live("click", function (e) {
                    e.preventDefault();
                    // $(this).dialog('destroy').remove();
                    $(this).closest(".dialog1").dialog("close");
                });
1
  • 1
    have you tried using .css() Commented May 8, 2013 at 9:33

5 Answers 5

3

You can use css() instead ofaddCss:

.css("background-color","red")

as well as live() is deprecated, you should use on() instead

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

1 Comment

as above will be required to call at all the places where ever dialog is initiated in the site we can easily override the css for all dialog.
0

use .css()

 $("<div></div>")
            .addClass("dialog1")
            .attr("id", $(this).attr("id"))
            .appendTo("body")
            .css("background-color","red")
            .dialog({
                title: $(this).attr("data-dialog-title"),
                close: function () { $(this).remove() },
                width: $(this).attr("data-dialog-width"),
                modal: true,
                position: 'center',
                resizable: $(this).attr("data-dialog-resizable")
            }).load(url);

and use on() instead of live()

            $(".close").on("click", function (e) {
                e.preventDefault();
                // $(this).dialog('destroy').remove();
                $(this).closest(".dialog1").dialog("close");
            });

delegate it ,if you are attaching this to dynamically generated element..

    $(document).on("click",".close", function (e) { //<--closest static element rather than document
                e.preventDefault();
                // $(this).dialog('destroy').remove();
                $(this).closest(".dialog1").dialog("close");
            });

Comments

0

Please consider using the following code:

$("<div></div>")
    .addClass("dialog1")
    .attr("id", $(this).attr("id"))
    .appendTo("body")
    .css("background-color","red")
    .dialog({
            ...

Important is the .css("background-color", "red")line.

Comments

0

You can make a change in the css itself

e.g. .ui-dialog {background:yellow}

Comments

0

simplest way is to override the jquery dialog background property as below

.ui-dialog .ui-dialog-content {
        background: red;
    }

Comments

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.