Swapping out the Close button on a JQueryUI Dialog pop-up

Despite my thorough search efforts on this topic, I have not been able to find a solution to my issue. Hopefully someone can assist me with this problem. I am working with a simple dialog box:

$("#dialog-search").dialog({
    resizable: false,
    height:dimensionData.height,
    width: dimensionData.width,
    modal: true,
    title: dimensionData.title,
    position: [x,y],
    open: function() {
        $("#dialog-search .dateField").blur();
    },
    close: function(event, ui){
       callBack(event,ui);
    }
});

My goal is to replace the default X icon (ui-icon-close) with a different icon provided by the UI (ui-icon-minus), so that clicking the minus icon closes the dialog instead. I have come across suggestions on hiding or customizing the icon with CSS, but I have yet to find a solution to directly replace the icon for the same functionality.

Edit: Additionally, I intend to use ui-icon-close for a different purpose in my dialog box by implementing a custom behavior/location. This might be beyond the scope of this question, but feel free to discuss if it aligns with a potential solution.

Answer №1

Understanding the dialog's structure can make it easier to manipulate.

http://jqueryui.com/demos/dialog/#theming

To change the close button icon, utilize the create event and switch the class to a different icon.

http://jsfiddle.net/Quincy/kHU2M/1/

$("#dialog-search").dialog({
    create: function(event, ui) { 
      var widget = $(this).dialog("widget");
      $(".ui-dialog-titlebar-close span", widget)
          .removeClass("ui-icon-closethick")
          .addClass("ui-icon-minusthick");
   }
});

Answer №2

Although this question is old, I wanted to share my solution in case it helps someone else. By using the following CSS, I was able to create a completely customized Close button UI. It may not be the most elegant solution, but it works perfectly for me.

.ui-icon-closethick {
    background-image: url(images/my-10px-image.png) !important;
    background-position: left top !important;
    margin: 0 !important;
}

.ui-dialog .ui-dialog-titlebar-close, .ui-icon-closethick {
    width: 10px !important;
    height: 10px !important;
}

.ui-dialog .ui-dialog-titlebar-close {
    background: none !important;
    border: none !important;
}

.ui-dialog .ui-dialog-titlebar-close, .ui-dialog .ui-dialog-titlebar-close:hover {
    padding: 0 !important;
}

Below is an example of my custom close button:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Does anyone know why the jQuery UI tooltip is not displaying above the element?

Could you kindly review my code on this JS FIDDLE? I'm trying to make my tooltip appear on top of the element, but it's not working. What am I missing? I couldn't find any helpful information about the position property in the jQuery UI do ...

What are some effective ways to restrict users from downloading the HTML template from a demo site?

I'm looking to start selling HTML templates online, but I'm realizing that creating a demo page may lead users to simply download the template without purchasing it. How do other sellers prevent this from happening? What strategies can ...

What are the steps to create a reliable menu?

Looking to add a fixed menu to my website that stays at the top even when scrolling down the page. For an example, check out iplex.co.in for a demonstration. ...

Why does the content not appear again when switching between tabs?

Hello! I'm facing an issue with toggling between two sets of content on my page. Initially, the correct content shows up, but when I switch tabs, the new content doesn't appear. Furthermore, if I click back to the first tab, that content disappea ...

What is the best way to use CSS to align an HTML form input box and buttons to the center?

Looking to replicate the design of the Google homepage on a certain HTML page. Struggling with centering the search bar and buttons using CSS. div.search { display: block; margin-left: auto; margin-right: auto; } <div class="search"> <form ...

What is the best way to select the initial descendant that matches a specific

How can we target only the first matching descendant element, without affecting others further down the hierarchy? For example: If the HTML structure is like this: <div class="wrapper"> <table> <tbody> <tr> < ...

What's preventing me from tapping on hyperlinks on my mobile device?

I'm currently working on a website (saulesinterjerai.lt) and everything seems to be functioning properly, except for the fact that on mobile devices, the links aren't clickable and instead navigates to other layers. How can I disable this behavio ...

The appearance of my sidebar items' right border varies depending on the web browser being used

My sidebar item's right border appears differently in Mozilla and Chrome. How can I resolve this issue? Here are the images from both browsers: https://i.stack.imgur.com/YGkkz.png https://i.stack.imgur.com/JxNs3.png "use client"; import { ...

Using Material-UI to showcase a TextField with a labelWidth set to zero

I need to showcase a specific field on my website. https://i.stack.imgur.com/PJUW7.png However, the issue I'm facing is that even when the field is in focus, the border remains unaffected and does not get cut off by the label. https://i.stack.imgur ...

Utilize the inherited background color for a linear-gradient effect

Here is the code snippet I am working with: <label className={classes.trigger} htmlFor={uniqueId} ref={labelRef} style={{ background: val, borderColor: val }} /> This is the corresponding CSS: .trigger { display: block; posit ...

Challenges encountered with progress bars

Currently, I am working on an Angular app and implementing a progress bar using Angular. However, I have encountered two issues with my progress bar that need to be addressed. The fourth section of web development is titled "from end," and I would like ...

Is it possible to create two header columns for the same column within a Material UI table design?

In my Material UI table, I am looking to create a unique header setup. The last column's header will actually share the same space as the previous one. Picture it like this: there are 4 headers displayed at the top, but only 3 distinct columns undern ...

Changing the Cursor with CSS Events

Is there a way to make the cursor change on a specific event without manually specifying every element that needs to change? For example, I want the cursor to switch from pointer to progress for all elements without having to list them individually like th ...

When placed within a <li> element, the <a> tag will not create a hyperlink to a page, but it will

I have encountered an issue with my anchor links. All of them are working properly except for the one in the second ul with an href="page1". Interestingly, the link shows the correct destination at the bottom left of my screen and works when I right-click ...

Creating a fluid 3-column layout using CSS and the float property

As a beginner in CSS, I am attempting to implement a 3 column layout on the CSS garden's HTML. The following is my approach: HTML: <div id="container"> <div id="pageHeader">Hello</div> <div id="quickSummary">Hello 1&l ...

Steps to ensure that the alert box size perfectly aligns with the width of the modal

Is there a way to resize the warning alert box so that it fits perfectly within the modal? https://i.sstatic.net/Mod1K.png Here is the code snippet: <div id="deleteCurso" class="modal fade" role="dialog"> ...

Add Django template without adding an extra line break

In my main.html template, I have the following code: <p>{% include "pouac.html" %}{% include "pouac.html" %}</p> The file pouac.html contains just one line: <span>pouac</span> When rendered, the main.html template generates two ...

I'm curious why this is happening. Is it due to the default padding or margin property?

I am currently working on a website project. The genre navigation menu is located in the bottom left container, and I had to use a negative margin property to position the li elements correctly. However, there seems to be an unexpected top padding of aro ...

Tips for creating a responsive HTML5 form

I am trying to center and make my form responsive. Can you help me achieve that with the code below? HTML5 Code <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html ...

Why doesn't "align-self: flex-end" relocate the game board to the bottom of the screen?

Hey there, I am currently working on developing a Connect 4 game and have decided to use a table for the board. To position the board properly, I am utilizing flexbox. Although I have specified align-items as 'flex-end' in order to bring it to th ...