views:

6163

answers:

7

Is it possible to open a jQuery UI Dialog without a title bar?

Thanks!

+9  A: 

I believe you can hide it with css:

.ui-dialog-titlebar { display:none; }

Or, specific to a particular item:

div#example .ui-dialog-titlebar { display:none; }

Checkout "Theming" the Dialog. I don't believe there is a dialog-option to not-render the title bar unfortunately.

Jonathan Sampson
Yes I guess that would work, but that's a global option. I was wondering if there was a way to do it with options.I guess I can do some pre rendering jquery'ness to remove the title div before it's shown.
Loony2nz
No. I don't believe there is an option to remove it. By default it is the close-button, so in a sense it's almost bad-design.
Jonathan Sampson
When people talk about css too much, they spell-funny, don't they
bobobobo
Also you probably shouldn't remove it since you can't move the dialog anymore after that. Probably better to put no text in it and restyle it so it is dark and thin
bobobobo
+4  A: 

I figured out a fix for dynamically removing the title bar.

$("#example").dialog(dialogOpts);
// remove the title bar
$(".ui-dialog-titlebar").hide();

This will remove all elements with the class 'ui-dialog-titlebar' after the dialog box is rendered.

Loony2nz
...and the css option removes any chance of them showing up before. I'm not sure I see any benefit in your alternative. In reality, your alternative is going to do what I did, only adding an extra step. Going the CSS-Route will be faster.
Jonathan Sampson
Well my option will only remove the title bar for this one dialog.If I used your option, I'd remove the title bar for all my dialogs.I can see in the future that I'll need a title bar.
Loony2nz
So you include your element within the css-rule: `#example .ui-dialog-titlebar...`. It will work either way; but the Javascript is going to set the css eventually, so I don't see the benefit of not doing it in css to begin with. It really doesn't make much of a difference - whatever you are most comfortable with :)
Jonathan Sampson
Is it just me or does #example not have scope over the dialog title?
Rio
+6  A: 

I think that the best solution is to use the option dialogClass.

An extract from jquery UI docs:

during init : $('.selector').dialog({ dialogClass: 'alert' });

or if you want after init. :

 $('.selector').dialog('option', 'dialogClass', 'alert');

So i created some dialog with option dialogClass='noTitleStuff' and the css like that:

.noTitleStuff .ui-dialog-titlebar {display:none}

too simple !! but i took 1 day to think why my previous id->class drilling method was not working. In fact when you call .dialog() method the div you transform become a child of another div (the real dialog div) and possibly a 'brother' of the titlebar div, so it's very difficult to try finding the latter starting from former.

mizar
+1 Jonatan's solution doesn't work for particular dialog. Your's does.
cetnar
A: 

You can use jquery to hide titlebar after using dialogClass when initializing the dialog.

during init :

$('.selector).dialog({

    dialogClass: 'yourclassname'

});

$('.yourclassname div.ui-dialog-titlebar').hide();

By using this method, you don't need to change your css file, and this is dynamic too.

Arun Vasudevan Nair
A: 

Actually there's yet another way to do it, using the dialog 'widget' directly:

You can get the Dialog Widget thus

$("#example").dialog(dialogOpts); $dlgWidget = $('#example').dialog('widget');

and then do

$dlgWidget.find(".ui-dialog-titlebar").hide();

to hide the titlebar within that dialog only

and in a single line of code (I like chaining):

$('#example').dialog('widget').find(".ui-dialog-titlebar").hide();

No need to add an extra class to the dialog this way, just go at it directly. Workss fine for me.

BearCode
A: 

Try this

$("#ui-dialog-title-divid").parent().hide();

replace "divid" by corresponding id

abdulkaderjeelani
A: 

I use this in my projects

$("#myDialog").dialog(dialogOpts);
// remove the title bar
$("#myDialog").siblings('div.ui-dialog-titlebar').remove();
Amirouche Douda