Jquery div mysteriously disappearing without explanation

I need some help with my image options. Whenever I hover over the image, the options appear below it. However, when I try to move down to select an option, they disappear. I have configured the slideUp function so that it only happens when the user moves away from the parent div.

$('.file-options').hide();
$('.file a img').mouseover(function(){
    $(this).closest('.file').find('.file-options').slideDown();
});
$('.file a img').closest('.file').mouseout(function(){
    $(this).find('.file-options').slideUp();
});

<div class="document">
  <div class="file">
    <a href="#"><img src="http://www.dermalog.com/images/pdf-icon.png" alt=""></a>
    <div class="file-options showhouse-text">
        <a href="#" onclick="return confirm('Are you sure you want to delete this file?');" class="show-tooltip" data-html="true" data-placement="top" data-original-title="Delete File">D</a>
        <a href="#" class="show-tooltip" data-html="true" data-placement="top" data-original-title="Edit File">E</a>
    </div>
  </div>
</div>

If you would like to see the code in action, check out the jsfiddle http://jsfiddle.net/5vAFh/2/

Answer №1

The triggering of the mouseout event from the <img> to the .file element is causing your code to hide the <div>. Consider using the mouseleave event instead, as it does not respond to events bubbling:

$('.file a img').closest('.file').mouseleave(function(){
    $(this).find('.file-options').slideUp();
});

Check out the demo here

Answer №2

Alternatively, you may consider this approach: demonstration http://jsfiddle.net/USBRy/

Verify with the statement if(!$(this).is(':hover')) {

Trust this explanation is beneficial :)

programming

$('.file-options').hide();

$('.file a img').mouseover(function () {
    $(this).closest('.file').find('.file-options').slideDown();
});

$('.file a img').closest('.file').mouseout(function (e) {
    if(!$(this).is(':hover')) {
        $(this).find('.file-options').slideUp();
    }
});

Answer №3

You were so close! Give this a try:

$('.file-options').hide();

$('.file').mouseover(function(){
    $(this).find('.file-options').slideDown();
});

$('.file').mouseout(function(e){
    if($(e.toElement).parents('.file').length < 1) {
       $(this).find('.file-options').slideUp();
    }
});

Check out the updated solution!

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

Dynamic loading and endless scrolling in jQuery with advanced filtering functionality

I have a page full of items that I filter by class names. This works great, but when I added lazy loading using ajax, it started causing some issues. Currently, I load the next page of items without applying the filter to the ajax call, and then hide the ...

What is the best way to position a button to the right side of the screen?

Is there a way to align a button to the right of a page? I attempted using text-align: right; and align-content: right; In addition, I want the button to utilize display: flex; #hideShow { display: flex; text-align: right; align-content: right; ...

Displaying dynamic content in JavaScript using Galleria module

Hello and thank you for taking the time to check out my question. I've encountered a little issue that I can't seem to solve by myself. I'm hoping someone could lend me a hand. On my website, there is a dynamic field filled with a code from ...

Is Ajax capable of processing and returning JSON data effectively?

I am in the process of making modifications to my codeigniter application. One of the changes I am implementing is allowing admin users to place orders through the admin panel, specifically for received orders via magazines, exhibitions, etc. To achieve ...

Transferring data via AJAX technology

My goal is to empower the ability to upload files using AJAX. I attempted to utilize (JavaScript) in this manner: $("input[type='file']").change(function(){ var file = document.getElementById("uploadelement").files[0]; $.ajax ...

Dynamically create a button using jQuery and JSON based on specific conditions (either true or false)

Is there a way to generate buttons with specified parameters only if a condition is true? Currently, the buttons are generated without checking conditions. Any help with the correct syntax would be appreciated. Sample JSON code: { "Caption": "Module ...

Retrieving and storing data using jQuery's AJAX caching feature

When utilizing jQuery's $.ajax() method to perform an XHR based HTTP GET request to obtain a partial of HTML from a Ruby on Rails website, I encounter an issue. Specifically, every time a user clicks on tabbed navigation, I refresh an HTML table with ...

Tips for creating a responsive Youtube embedded video

Check out this website for a good example: If you take a look, you'll notice that the header youtube video is responsive - it automatically resizes when the window size changes. Here are the <iframe> codes: <iframe id="bluetube-player-1" fr ...

How can I create a dynamic height for a scrollable div?

How can I build a section with a defined height that contains a sticky header (with a dynamic height) and a scrollable body? I want the body to be scrollable, but due to the header's changing height, I'm unable to set an exact height. What should ...

How can `timeout` be activated for `$.ajax({dataType:'jsonp'...` in jQuery? Any viable solutions?

Does anyone know how to enable a timeout for the $.ajax function when using the dataType:'jsonp' option? I have tried setting the timeout to 200 milliseconds but it doesn't seem to work. Here is a reference link: http://jsfiddle.net/laukstei ...

Troubleshooting Bootstrap image alignment problem with columns on extra small screens

My website showcases screenshots of my software in a div element. Everything looks great on larger screens, but once I switch to a phone or resize the window, the images don't align properly, leaving empty space. Refer to the image below for clarifica ...

Is there a way to continually repeat a hover effect?

Currently, I am focusing on creating a timeline and have managed to get the basic function working in jQuery. You can view my progress on jsFiddle here: http://jsfiddle.net/Jason1975/6nwkd2c8/38/ The issue I am facing is that I cannot get the hover effect ...

Understanding the Intrinsic Dimensions of Replaced Elements in CSS

I'm currently facing some challenges with the CSS Intrinsic & Extrinsic Sizing Module Level 3, specifically chapter 4.1 on Intrinsic Sizes. This section is proving to be quite difficult for me: When a block-level or inline-level replaced element h ...

Is it possible to generate a "pop-up" window upon clicking on the register button?

As a backend programmer, I'm looking to create a popup window that appears in front of the current window when users click "register", eliminating the need for redirection to another page. I believe you understand the concept. How can I achieve this? ...

Issue with preventdefault() function in Internet Explorer 8

I've encountered a problem while working on a page that heavily utilizes ajax. Everything seems to be functioning well across different browsers, except for one final step that is broken in IE8 and below. You can view the issue on this demo page: To ...

A simple guide on how to surround every incorrect input index in mapped inputs with red borders

I am incorporating a modal that corresponds each element of the object newCompanies to a specific row: {newCompanies.map((company, index) => { return ( <div> <div className="side- ...

What value is used as the default for justify content?

MDN states that the default value of justify-content is normal, even though it's not listed in the accepted values. What exactly does a normal value mean? normal This means that items are packed in their default position as if no justify-cont ...

Tips for extracting links from a webpage using CSS selectors and Selenium

Is there a way to extract the HTML links per block on a page that renders in JavaScript? Would using CSS or Selenium be more effective than BeautifulSoup? If so, how would I go about utilizing either of those methods to achieve the extraction of the HTML ...

How to switch between classes for elements and return to the original one when none of the elements is chosen

Hello there, I need some assistance. Here's the scenario: I am working with a grid of six items. My goal is to have the first item in the grid become active by default. When the user hovers over any of the remaining five items, I want the active clas ...

How can you ensure your CSS code is functional across various browsers?

I have been exploring CSS and HTML for about a week now, but I am facing a challenge that has me stuck for the past thirty minutes. The issue lies in adapting this code to work smoothly across different browsers. While it aligns images in a row of four per ...