The jQuery UI dialog stubbornly refuses to close when tapped, yet opens without hesitation

I'm struggling to understand why my dialog boxes are not closing when I tap outside of them. I've tried using different selectors such as document, window, .ikon_picmap, but nothing seems to be working. What am I missing here?

Check out the code here

Here is the JavaScript code:

//Document Ready
$(document).ready(function(){

// Hiding the modals initially
$( "#p1_box" ).dialog({ autoOpen: false });
$( "#p2_box" ).dialog({ autoOpen: false });
$( "#p3_box" ).dialog({ autoOpen: false });
$( "#p4_box" ).dialog({ autoOpen: false });

// Positioning the modals relative to their triggers
$('#p1_box').dialog({position: {my:'left+5% top+4%',at:'top', of:'.p1'}});
$('#p2_box').dialog({position: {my:'left+5% top+4%',at:'top', of:'.p2'}});
$('#p3_box').dialog({position: {my:'left+5% top+4%',at:'top', of:'.p3'}});
$('#p4_box').dialog({position: {my:'left+5% top+4%',at:'top', of:'.p4'}});

$('.p1').mouseenter(function(){
    $( "#p1_box" ).dialog( "open" );
});
$('#p1_box').mouseleave(function(){
    $('#p1_box').dialog('close');
});
$('.p2').mouseenter(function(){
    $( "#p2_box" ).dialog( "open" );
});
$('#p2_box').mouseleave(function(){
    $('#p2_box').dialog('close');
});
$('.p3').mouseenter(function(){
    $( "#p3_box" ).dialog( "open" );
});
$('#p3_box').mouseleave(function(){
    $('#p3_box').dialog('close');
});
$('.p4').mouseenter(function(){
    $( "#p4_box" ).dialog( "open" );
});
$('#p4_box').mouseleave(function(){
    $('#p4_box').dialog('close');
});

//    Touch Commands
$('.p1').on("tap",function(){
    $( "#p1_box" ).dialog( "open" );
});
$('.p2').on("tap",function(){
    $( "#p2_box" ).dialog( "open" );
});
$('.p3').on("tap",function(){
    $( "#p3_box" ).dialog( "open" );
});
$('.p4').on("tap",function(){
    $( "#p4_box" ).dialog( "open" );
});


});  // End Document Ready

// On window resize (for correct modal trigger placement) - a responsive feature
$(window).on('resize', function(){

$('#p1_box,#p2_box,#p3_box,#p4_box').dialog('close');

}); // End window resize

And here is the CSS code:

.p1 {
left:53%;
top:40%;
color: #0FA0CE;
}
.p2 {
left: 63%;
top: 21%;
color: #0FA0CE;
}
.p3 {
left:52%;
top:14%;
color: #0FA0CE;
}
.p4 {
left:18%;
top:65%;
color: #0FA0CE;
}
/* Picmap position markers END */

/* Global Non-Responsive Styles */
html {
width:100%;
height: 100%;
}
/* Don't show the "x" on the diag box */
.ui-dialog-titlebar-close {
visibility: hidden;
}
.ikon_picmap {
background-color: #bbbbbb;
position: relative;
display: block;

}
.ikon_picmap img {
width: 100%;
height: auto;
/*position: absolute;*/
}
.ik_p {
cursor: pointer;
height: 10px;
width: 10px;
position: absolute;
font-size: 1em;
}

Any assistance on this issue would be greatly appreciated!

Answer №1

Consider implementing the mouseleave event on .ui-dialog rather than on individual dialog elements like this:

HTML

<div id="p1_box" class="p_box" title="Nose">
  <p>This is where the dog breaths from.. pretty neat.</p>
</div>
<div id="p2_box" class="p_box" title="Left Ear">
    <p>This is one of the wonderful ears used by this puppy to listen to things.</p>
</div>
<div id="p3_box" class="p_box" title="Right Ear">
    <p>Make sure he doesn't hear you out of this ear..</p>
</div>
<div id="p4_box" class="p_box" title="Toy">
    <p>A much needed thing for a puppy.  Probably shouldn't have a puppy without a toy.</p>
</div>

SCRIPT

$('.ui-dialog').mouseleave(function(){
    $(this).find('.p_box')
           .dialog('close'); // p_box is the element for which the dialog opens
});

Also, ensure that you only call the dialog function once for multiple properties like so:

$('#p1_box').dialog({
   autoOpen: false,
   position: {my:'left+5% top+4%',at:'top', of:'.p1'}
});

Check out the JsFiddle link for reference

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

HTML code causing an Ajax post request to return a null value

How can I send JSON data from HTML to PHP using the Ajax post method? I have looked at various resources like this and this but so far, I am only getting a null return value. Other similar questions have not been helpful either. HTML (jQuery Ajax): $(&apo ...

Older versions of Internet Explorer, specifically IE 8 and below, are causing issues with iframe

I am currently working on a website that includes an embedded Vimeo video. The majority of our target audience uses IE8 or older, and interestingly enough, most of them have their browsers zoomed to 125% view. Unfortunately, while everything else on the si ...

Resolving DataTables Error

Here is my JavaScript code snippet. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.2.1/css/but ...

Generate a custom image using a pre-existing background image and text using JavaScript, then save it as a JPEG file in

Managing multiple fanpages on Facebook can be quite a task, especially when it comes to posting images with funny text. I have different backgrounds for each page, which means I have to save each image individually with the text. To streamline this process ...

Using jQuery to Construct an Object from a JSON Response

After receiving a JSON response from a PHP file via an AJAX call, I successfully retrieved the data. console.log(data["json"]); [{"value":"23","label":"Assorted Juices"},{"value":"24","label":"Water"},{"value":"25","label":"Beers"},{"value":"26","label": ...

Error 500: Issue with JQuery AJAX File Upload

Hey there, I'm facing an issue with doing a file upload using JQuery's AJAX feature as I keep getting the error 500. $(function() { $( 'form' ).submit ( function() { $.ajax({ type: &a ...

Flexbox properties are being ignored by input fields

Hey there, I'm currently working on a product calculator and need to create 9 input fields organized in 3 rows of three columns. However, when I try to use display: flex and flex-direction: row on the parent div, it doesn't seem to be working as ...

Changing the href of an image when the slide changes: Tips and tricks

Currently, I am utilizing the slick slider slideshow and facing an issue with updating the href of a logo image as the slides progress. Despite trying out two different scripts, none of them have proven to be effective. <main class="Site-content"> & ...

Using jQuery Ajax to send data and retrieve responses in the Codeigniter framework

I am struggling with passing values in CodeIgniter and I need some guidance. Could you provide an example code snippet using CodeIgniter to send a value from a view to a controller using Ajax and jQuery, and then display the result on the same page? In my ...

I require assistance in developing a mouseover image link that conceals the top image and unveils a bottom image that scrolls vertically in the exact same area as the top

I am trying to achieve a similar effect as shown on: this website I require assistance in creating a mouseover image link that hides the top image and reveals a bottom image that scrolls vertically within the same space as the top image. The long vertica ...

The CSS 'd' attribute for the <path> element is not functioning properly in Firefox

My generated code cannot be directly modified due to its association with a large JS code. A portion of this code creates an SVG shape, which I attempted to override through CSS. However, my solution does not function properly in Firefox! Below is the ori ...

Adjust the product percentage discount color in WooCommerce

I am struggling to switch the box color of the percentage discount for each product from green to red. I tried modifying the function I found on Reddit, but I couldn't get it right and it caused a fatal error, crashing the entire website. Here is the ...

Placing a div within a 960 grid system can sometimes result in unexpected spacing

Testing on various browsers: Chrome, IE, Firefox. I'm facing an issue where the BusinessNav ID keeps getting pushed over 3 columns. Desired page layout can be found here I could definitely hack this code to adjust the positioning. However, with so m ...

Transform data into JSON format using AJAX in CodeIgniter

I am having trouble with converting json code in CodeIgniter for pagination. I am using ajax to control the data conversion to json and sending it to the view. Can someone please explain how to do this? In the controller, instead of using a foreach loop, ...

Issue with Highcharts failing to render points on regular intervals

I am facing an issue where the line graph in my frontend application using highcharts disappears or fails to draw to the next new data point every 30 seconds. Can anyone provide insight into why this might be happening? Check out the fiddle: http://jsfidd ...

Shift the column upwards for devices with smaller screens

I need help with a layout issue I am facing. Currently, my layout looks like this: [blurb] (8) [form] (4) However, I want the [blurb] to take up col-md-8 and the [form] to take up col-md-4 so that they are full width on smaller devices. On smaller devic ...

Resolve the issue pertaining to the x-axis in D3 JS and enhance the y-axis and x-axis by implementing dashed lines

Can anyone assist with implementing the following features in D3 JS? I need to fix the x-axis position so that it doesn't scroll. The values on the x-axis are currently displayed as numbers (-2.5, -2.0, etc.), but I want them to be shown as percentag ...

Updating the design of mui stepper icon

Is there a way to change the color of this icon from https://i.sstatic.net/kr5lv.png I would like it to be this color: https://i.sstatic.net/dHh68.png I have tried using .Mui-disabled but it didn't work, not sure if it's .Mui-active or .Mui-com ...

An issue is being caused by altering the custom.scss.css file in Rails

After following the tutorial by Michael Hartl (), I encountered an issue when trying to modify some CSS functions in the custom.scss.css stylesheet. Every time I make a change, such as adjusting the margin from 10 px to 11 px, I receive this error in my br ...

Managing multiple carousels simultaneously using the middle mouse button in Swiper.js

I am currently utilizing 5 carousels on my screen, all of which are operated by the same navigation buttons. In addition to this, I require the ability to control them using the middle mouse scroll. However, when I activate the mouse wheel control, only ...