Icons in jQuery UI dialog title

I'm using the code below to create a jQuery dialog box. By default there is a close icon on title bar, but I want to add some of the other icons in title bar as well for different functionality.

The code used for the dialog box is:

$("document").ready(function () {
        title: "Dialog Title",
        height: 400,
        width: 500

I'm using following .css and .js files:

<link type="text/css" href="jquery-ui-1.7.3.custom.css" rel="stylesheet" />
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jquery-ui-1.7.3.custom.min.js"></script>


You can define HTML in the title option when creating the dialog box. Therefore, using the existing jQuery UI icon sprites, we can use this Javascript:

For jQuery UI 1.10.0

You need to override the undocumented _title function, according to Bug #6016 to ensure that the title attribute is not escaped.

var dialog = $("#dialog").dialog();

dialog.data( "uiDialog" )._title = function(title) {
    title.html( this.options.title );

dialog.dialog('option', 'title', '<span class="ui-icon ui-icon-home"></span> Example Dialog');
For older versions
    title: '<span class="ui-icon ui-icon-home"></span> Example Dialog'

And this CSS

.ui-dialog .ui-dialog-title .ui-icon {
    float: left;
    margin-right: 4px;

To add an icon to the title of the dialog. You can see the complete set of jQuery UI icons here: http://jqueryui.com/themeroller/

To see this working, live, see: http://jsfiddle.net/XkSu9/ (jQuery UI 1.10+) or http://www.jsfiddle.net/yijiang/UYMJH/ (old version)

You can do that by adding some HTML code to title bar when dialog opened.

$("document").ready(function () {
            title: "Dialog Title",
            height: 400,
            width: 500,
            open: function(event, ui){
                $(this).parent().find('.ui-dialog-titlebar').append('Some HTML');

A much simpler method. In the stylesheet:

.ui-dialog .ui-dialog-title {
  background-image: url('/icons/info.png');
  background-repeat: no-repeat;
  padding-left: 20px;

This is for a 16x16 image.

Here is how you solve the jQuery UI 1.10.0 dialog title issue globally instead of one object at a time:

jQuery.widget('ui.dialog', jQuery.extend({}, jQuery.ui.dialog.prototype, {
    _title: function(titleBar) {
        titleBar.html(this.options.title || '&#160;');

Now use the dialog widget as usual and your titles won't get escaped anymore.

I did it this way:

<script type="text/javascript" language="javascript">
    function MsgBox() {
        var arg = arguments;
        0 = message
        1 = title
        2 = width
        3 = height
        4 = command to evaluete if Ok is clicked (optional)
        $("body").append("<div id=\"dlgMsg\" title=\"" + arg[1] + "\">" + arg[0] + "</div>");
            autoOpen: false,
            modal: true,
            bgiframe: true,
            width: arg[2],
            height: arg[3],
            close: function (event, ui) { $(this).dialog("destroy").remove(); },
                    'OK': function () { if (arg[4]) eval(arg[4]); $(this).dialog("close"); }

        return false;

Usage: MsgBox("Hello, I'm a MessageBox!", "Title Here", 400, 200);


MsgBox("Hello, I'm a MessageBox!", "Title Here", 400, 200, "alert('hey, you clicked Ok!')");

You may improve it with ui-icons as well...

Need Your Help

Make specific corners of UIView round

iphone ios uiview

I did a bit of research, and I see, there is no easy way to