0

jQuery UI themes are nice they apply to the entire document, however I have some cases where the style of the dialog such as the title bar colour must be changed.

In my jQuery UI css, the titlebar is coded:

.ui-dialog .ui-dialog-titlebar { padding: .4em 1em; position: relative; }

Here's my javascript:

var $AlertDialog = $('<div"></div>')
.dialog({
  autoOpen: false,
  title: 'Alert Message',
  buttons: {Ok: function() {$( this ).dialog( "close" );}}
});     

function Alerter(cTxt)
{
  $AlertDialog.html(cTxt);
  $AlertDialog.css('ui-dialog-titlebar','color: red');
  $AlertDialog.dialog('open');
};

Alerter() is then called as a substitute for alert().

Accessing and altering the color property of 'ui-dialog-titlebar' has no effect.

Lots of reading preceded this question. Seems others have had similar issues, but not specific to jQuery UI.

How can this be done?


Update:

Thanks to a good hint, I did this:

$AlertDialog.dialog('open');
$("#.ui-dialog .ui-dialog-title").css('color','red');
$("#.ui-dialog .ui-dialog-title").css('background-color','orange');

Works. But acceptable practice?

1
  • 1
    Why not add a class and style it with CSS? Commented Oct 15, 2011 at 20:18

2 Answers 2

1

My suggestion would be to not use the .ui-dialog selector as there may be more than one dialog on a page. You can traverse to the title bar.

    ...
    $AlertDialog.html(cTxt);
    // might as well use the theme since its part of jquery ui
    $AlertDialog.prev().addClass("ui-state-error");
    $AlertDialog.dialog('open');
Sign up to request clarification or add additional context in comments.

Comments

0

Firstly,

According to documentation .css() takes property as param.
It seems you are trying changing ui-dialog-titlebar. Instead try this:

...
function Alerter(cTxt)
{
  $AlertDialog.html(cTxt);
  $AlertDialog.dialog('open');
  $(".ui-dialog .ui-dialog-title").css('color','red'); 
  $(".ui-dialog .ui-dialog-title").css('background-color','orange'); 
  //Assuming you want to change header color only
  //see the theming structure at http://jqueryui.com/demos/dialog/#theming
};

2 Comments

$moguzalp You provided a great hint. Using > span produced an error, but I got it another way.
$AlertDialog.dialog('open'); $("#.ui-dialog .ui-dialog-title").css('color','red'); $("#.ui-dialog .ui-dialog-title").css('background-color','orange');

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.