Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an image to the ui-dialog-titlebar in JQuery?

It is possible to add an image to the ui-dialog-titlebar into a dialog box?.

like image 723
Felix Avatar asked Jan 20 '26 01:01

Felix


2 Answers

It sure is. Making it look pretty in terms of sizing and alignment will be the tricky part. But placing an image in the titlebar should be as simple as:

$(".ui-dialog-titlebar").append("<img src='felix.gif' id='myNewImage' />");

Edit:
Building on what Nick said below (cheers), if you wanted to be really hardcore, you would place the code inside the open event of the dialog, ie:

$(".putSelectorHere").dialog({
  open: function(event, ui) {
    $(".ui-dialog-titlebar").append("<img src='felix.gif' id='myNewImage' />");
  }
});

Click for relevant docs.

like image 92
GlenCrawford Avatar answered Jan 21 '26 19:01

GlenCrawford


if you use

 $(".ui-dialog-titlebar").append("<img src='felix.gif' id='myNewImage' />");

on open event then first remove felix.gif

$(".ui-dialog-titlebar").remove("#myNewImage");

because if you open dialog box more than once it will add same image more than once or destroy dialog box

like image 36
Prasanna Kulkarni Avatar answered Jan 21 '26 19:01

Prasanna Kulkarni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!