Click here to Skip to main content
15,906,947 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, i have a problem getting the title of the dialog

this is the code, gut the alert that pops up says [object], [object]
i have tried many different sollutions but it's not working

i have to get the title dynamic and can't call the dialog id direcly.

the ID of the
C#
$('.ui-dialog-titlebar').mouseup(function () {
    alert($(this).parent().children('#ui-dialog-title-dialog').dialog("option", "title"));
});


i have googled it, but haven't found the solution.

does any one know the solution, thanks!
Posted

You are calling the dialog function (.dialog) in line there. That will return a jQuery wrapped object

The title of the dialog is exactly what you've specified in the arguments dialog("option", "title")!

Here is some HTML generated by the .dialog function

HTML
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
    Dialog Title
    <a href="#" class="ui-dialog-titlebar-close ui-corner-all" role="button">
    close</a>
</div>


So really, what you want to do is get the child of the ui-dialog-titlebar class element, which should read like this

$('.ui-dialog-titlebar').mouseup(function () {
    alert($(this).children('#ui-dialog-title-dialog').text());
});



The order of events is important in jQuery. We're trying to attach an event handler to an element that is dynamically created by the .dialog function. Therefore, we can only attach the handler after the dynamic HTML has been generated.

e.g.

C#
// This creates the dialog
$("#dialog").dialog();

// Now we attach the handler
$('.ui-dialog-titlebar').mouseup(function () {
    alert($(this).children('#ui-dialog-title-dialog').text());
});
 
Share this answer
 
v4
Comments
CrafterIt 24-Feb-11 9:53am    
i tried yuor solution but the alert outputs this:

function (a) {
if (c.isFunction(a)) {
return this.each(function (b) {var d = c(this);d.text(a.call(this, b, d.text()));});
}
if (typeof a !== "object" && a !== B) {
return this.empty().append((this[0] && this[0].ownerDocument || t).createTextNode(a));
}
return c.text(this);
}
Dylan Morley 24-Feb-11 10:15am    
Please see my amendment about order of events - I just tested that & correctly see the Dialog Title Text
It worked with this JQuery code

var page = $(this).parent().find('.ui-dialog-content').dialog("option", "title");

guess i needed to sleep on it :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900